typelits - Haskell

Welcome to the Functional Programming Zulip Chat Archive. You can join the chat here.

HateUsernames007

Is there an equivalent of symbolVal for Char like charVal :: forall n proxy. KnownChar n => Char? I am trying to realize the char kind in runtime.

Georgi Lyubenov // googleson78

don't think so, what are you trying to do?

TheMatten

There isn't support for type level chars yet - issue on GHC tracker exists, I just can't find it :big_smile:

Jakob Brünker

https://gitlab.haskell.org/ghc/ghc/-/merge_requests/3598

The patch fixes #11342. In this patch, we introduced the Char Kind, a kind of type-level characters, with the additional type-families, type-level counterparts of functions from the `Data.Char` module. We...
HateUsernames007

I am trying to strip the prefix chars from a JSON string. I would like to specify which char to strip at the type level.

newtype StripPrefixes (c :: Char) a = StripPrefixes a
instance FromJSON a => FromJSON (StripPrefixes c a) where parseJSON = ...
Georgi Lyubenov // googleson78

at least you can strip entire strings for now instead so it's not a blocker (?)

Georgi Lyubenov // googleson78

if you're interested, here's some hacky stuff with Symbols - https://kcsongor.github.io/symbol-parsing-haskell/

A technique for manipulating Symbols in GHC for type-level programming.
Georgi Lyubenov // googleson78

I'd wager you can use these things to error out if the user uses a Symbol with more than one character :thinking:

HateUsernames007

Currently just doing

instance (KnownSymbol s, FromJson a) => FromJSON (StripPrefixes s a) where
  parseJSON = case prefix of
    "" -> parseJSON
    _ -> \case
      String x -> whileJust (T.stripPrefix prefix) >>> String >>> parseJSON
      _ -> fail "Expecting String"

whileJust :: (a -> Maybe a) -> a -> a