Monday, April 18, 2011

Type-Class Silliness

The first code example of this post is a perfect example of how type classes are over-used, how the newtype hack makes matters worse, and why Global Script uses functors instead. In Global Script, it would be:

liftedMonoid :: ∀ 'f 'm. applicative.t f → monoid.t m → monoid.t (f m);
implicit liftedMonoid (module applicative.c);
'liftedMonoid (module 'app) (module 'mon) = 〈
    'id = app.return;
    'op = map2 @(module app) mon.op;
More re-usable and no silly newtype wrapper.
Oh, and by the way: to use the above to write an instance for (→), if Global Script had a monoid type class (which it doesn't need):

instance module monoid.c ('α → 'β) | module monoid.c β =
    liftedMonoid (instance module monoid.c β)