ConstraintKinds and default associated empty constraints

Antoine Latter aslatter at gmail.com
Mon Jan 9 07:41:51 CET 2012


On Mon, Jan 9, 2012 at 12:30 AM, Antoine Latter <aslatter at gmail.com> wrote:
> On Sun, Jan 8, 2012 at 11:21 PM, wren ng thornton <wren at freegeek.org> wrote:
>>
>>
>> Couldn't the following work?
>>
>>
>>    class Functor f where
>>        type C f :: * -> Constraint
>>        type C f _ = ()
>>
>
> I get a parse error from that.
>
> The equivalent:
>
>   class Functor f where
>       type FC f :: * -> Constraint
>       type FC f a = ()
>

The definitions are accepted by GHC:

   class Functor f where
       type FC f a :: Constraint
       type FC f a = ()

       fmap :: (FC f a, FC f b) => (a -> b) -> f a -> f b

   instance Functor [] where
       fmap = map

But I don't like the 'a' being an index parameter, and then the
following expression:

   fmap (+1) [1::Int]

Gives the error:

    Could not deduce (FC [] Int) arising from a use of `fmap'
    In the expression: fmap (+ 1) [1 :: Int]
    In an equation for `it': it = fmap (+ 1) [1 :: Int]

> gives the error:
>
>    Number of parameters must match family declaration; expected 1
>    In the type synonym instance default declaration for `FC'
>    In the class declaration for `Functor'
>
>> It seems to me that adding const to the type level (either implicitly or
>> explicitly) is cleaner and simpler than overloading () to be Constraint,
>> *->Constraint, *->*->Constraint,...
>>
>> --
>> Live well,
>> ~wren
>>
>>
>> _______________________________________________
>> Glasgow-haskell-users mailing list
>> Glasgow-haskell-users at haskell.org
>> http://www.haskell.org/mailman/listinfo/glasgow-haskell-users



More information about the Glasgow-haskell-users mailing list