I'm trying to learn GHC Generics. After reviewing several examples, I wanted to try to create a generic Functor
instances (disregarding that GHC can derive them automatically for me). However, I realized I have no idea how to work with a parametrized data types with Generics, all the examples I've seen were of kind *
. Is this possible, and if yes, how? (I'm also interested in other similar frameworks, such as SYB.)
相关问题
- Generic Generics in Managed C++
- Caugth ClassCastException in my Java application
- Understanding do notation for simple Reader monad:
- Making Custom Instances of PersistBackend
- Haskell: What is the differrence between `Num [a]
相关文章
-
What is the difference between
and in java - Is it possible to write pattern-matched functions
- Haskell underscore vs. explicit variable
- Top-level expression evaluation at compile time
- C# generics class operators not working
- Stuck in the State Monad
- Generics and calling overloaded method from differ
- foldr vs foldr1 usage in Haskell
There is a
Generic1
class for data types of kind* -> *
. Working with it is mostly the same as with data types of kind*
, except there's alsoPar1
for the parameter. I've used it in my unfoldable package for example.The best place to look for lots of example functions using GHC Generics is the
generic-deriving
package. There's a generic definition of theFunctor
class in there. Copying (slightly simplified) fromGenerics.Deriving.Functor
:To use this on a datatype, you have to derive
Generic1
rather thanGeneric
. The key difference of theGeneric1
representation is that it makes use of thePar1
datatype that encodes parameter positions.