[Haskell-cafe] Type-class predicates head-normal forms

11 views
Skip to first unread message

sheng chen

unread,
Jun 22, 2016, 1:31:25 AM6/22/16
to haskel...@haskell.org
Hello,

I got a question about what the form of types in Haskell are allowed. Specifically, what are the requirements of the context of a type? The paper

    Typing Haskell in Haskell

required the type to be in the form P => t, where P to be in head-normal form or in other words shouldn't be something like Num Bool.

Now what about multi-parameter classes? The paper

    Type classes: an exploration of the design space

listed several potential choices but didn't say exactly what.

The Haskell 2010 report covered single-parameter type classes only.

Given the following definition.

class Collects ce e | ce -> e where
    empty :: ce
    insert :: e -> ce -> ce
   
insert2 c = insert True (insert False c)

The function insert2 has the following type

insert2 :: Collects ce Bool => ce -> ce

This shows that the definition of head-normal forms for multi-parameter class differs from that for single-parameter classes. Is there any definite specification about the context of Haskell types?

Thank you,
Sheng

adam vogt

unread,
Jul 1, 2016, 9:18:26 AM7/1/16
to sheng chen, haskell-cafe

Hi Sheng,

Maybe MPTCs can be explained as syntax sugar for extensions that might be (more easily) specified. http://lpaste.net/168659 has one version using type equality (GADTs here), and another that depends on user discipline. I think both translations need FlexibleInstances/FlexibleContexts.


Regards,

Adam


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

Reply all
Reply to author
Forward
0 new messages