In Haskell, I might write a typeclass with a type
declaration to create a type family, like so:
class ListLike k where
type Elem :: * -> *
fromList :: [Elem k] -> k
And then write instances like this:
instance ListLike [a] where
type Elem [a] = a
fromList = id
instance ListLike Bytestring where
type Elem Bytestring = Char
fromList = pack
I'm aware that you can create typeclasses and type-level functions in Idris, but the methods operate on data of the given type, not the type itself.
How can I make a typeclass-constrained type family in Idris like the one above?
Elem
as a function – Random Dev