Local definitions in the class instances

Max Bolingbroke batterseapower at hotmail.com
Tue Feb 1 10:52:06 CET 2011


On 27 January 2011 17:11, Iavor Diatchki <iavor.diatchki at gmail.com> wrote:
> instance Num Wrapped where
>    local
>      lift2 f (Wrapped a) (Wrapped b) = Wrapped (f a b)
>      lift f (Wrapped a) = Wrapped (f a)
>    in
>     (+) = lift2 (+)
>     (-) = lift2 (-)
>     (*) = lift2 (*)
>     abs = lift abs
>     signum = lift signum

Local declarations at module scope can be emulated using pattern bindings:

"""
(foo, bar) = (foo, bar)
  where
    foo = ..
    bar = ..
    private = ...
"""

If instance declarations supported pattern bindings you could get the
same effect for your instances too. This would be a minimal change
that avoided introducing any extra syntax.

Cheers,
Max



More information about the Haskell-prime mailing list