I’m mixing some fun magic in my cauldron over here (details below), and I’m in need of a few utility types and functions. But I do not know where to find these if they exist, where to make PRs if libraries that do this sort of thing exist (but perhaps don’t address my specific needs), or where to put these definitions myself so that other people can find them. Hoogle is markedly less helpful in finding types of a certain shape than for finding functions with a certain type.
The two utilities I need this particular moment are
type List = [] -- avoid punning
-- | An indexed-heterogeneous list @FList f xs@, where each element has the same type @f@ but
-- with a different index @xs@.
type FList :: forall k. (k -> Type) -> List k -> Type
data FList f xs where
FNil :: FList f '[]
(:>>) :: f x -> FList f xs -> FList f (x : xs)
infixr 5 :>>
-- | Convert the representation of a list of compile-time data to a list of representations
typeRepList :: TypeRep @(List k) xs -> FList TypeRep xs
typeRepList = ...
Has anyone spotted these beasts in the wild? Any advice on how I might track them down? If I wish to release these beasts myself, any advice on where I should put them so others can find them?
If you’re curious, the magic I’m cooking is to allow the ability to look up and use class instances at runtime, so that if you know the name of a type (as a Text
), you can get and use instances for that type. Note in [this StackOverflow post]Deserializing to different types at runtime in haskell - Stack Overflow), the first comment on the original post says “This can not be achieved, I think.” When I see someone say that about an idea in Haskell, I take it as a direct challenge.