the constant functor

Tom Pledger [email protected]
Wed, 28 Mar 2001 08:46:08 +1200

Tobias Haeberlein writes:
 | > What is wrong with:
 | > 
 | >   class Functor ConstInt where
 | >     map f (Const n) = Const n
 | Ups - absolutely nothing.
 | I actually tried it with 
 |  data ConstInt a = Int

This version doesn't refer to the type Int.  Instead, it introduces a
new nullary data constructor called Int, which you could use like

    instance Functor ConstInt where
        fmap f Int = Int

...but I don't think that's what you were after.  If you use a type
alias (type ConstInt a = Int) instead of declaring a data type, it
will refer to the type Int.  However, then you'd need to use ConstInt
partially applied in the instance declaration, which Haskell doesn't
allow.  I think Gofer has a more liberal type system which does allow

 | and didnt manage to make this an instance of
 | class Functor. Sorry for giving the wrong 
 | example.