
For a datatype like data T a = Cons a I could define 'seq' myself as seq (Cons _) x = x if it would be a type class method. Is there a type class for generating the constructor independently from the input, as in: force ~(Cons x) = Cons x ?

On Sun, Jun 5, 2011 at 4:01 AM, Henning Thielemann
For a datatype like data T a = Cons a I could define 'seq' myself as seq (Cons _) x = x if it would be a type class method.
Is there a type class for generating the constructor independently from the input, as in: force ~(Cons x) = Cons x ?
So force will "push down" the lazyness one level in some sense? Would this only work for unary constructors of data declarations (not newtypes)? so force _|_ = Cons _|_ John

On 5 June 2011 12:01, Henning Thielemann
Is there a type class for generating the constructor independently from the input, as in: force ~(Cons x) = Cons x
This is related to eta expansion. I don't think there is a type class for this in the standard libraries. As John pointed out it only makes sense for unary data types, functions and newtypes over those things. An interesting restriction is that you apparently cannot define "force" (what I would call "eta") for unary data constructors with *existential* type variables without using unsafeCoerce. Max
participants (3)
-
Henning Thielemann
-
John Meacham
-
Max Bolingbroke