[m-users.] Typeclasses question

Volker Wysk post at volker-wysk.de
Tue Oct 21 17:44:53 AEDT 2025


Hi!

In Haskell, not only types can be members of a typeclass, but also type
constructors. Here's an example:

https://downloads.haskell.org/ghc/latest/docs/libraries/base-4.21.0.0-8bb5/Data-Functor.html

I want to build this typeclass, following the Haskell typeclass "Functor":

:- typeclass functor(A) where [
    func fmap(func(X) = Y, A(X)) = A(Y)
].

"A" is a type constructor. 

With this, you could do, for instance:

fmap(func(X) = X+1, maybe(2))

and get maybe(3).


Cheers,
Volker


More information about the users mailing list