[Haskell-cafe] how to factorize propagation of a function over a data type
TP
paratribulations at free.fr
Mon Dec 2 22:28:07 UTC 2013
TP wrote:
> propagate :: Bar -> (forall a. (FooClass a) => a->a) -> Bar
In fact, I do not understand why we have to add the typeclass constraint
(FooClass a).
Indeed, there is no mention to foo1 and foo2 functions (members of the
FooClass typeclass) in the code of propagate:
-------
propagate v f = case v of
Bar1 i -> Bar1 (f i)
Exp1 b1 b2 -> Exp1 (propagate b1 f) (propagate b2 f)
Exp2 b1 b2 -> Exp2 (propagate b1 f) (propagate b2 f)
-------
propagate deals with any function a priori, not only foo1 and foo2. So how
to understand the need for this typeclass constraint?
TP
More information about the Haskell-Cafe
mailing list