[Haskell-cafe] Re: forall (What does it do)

John Creighton johns243a at gmail.com
Thu May 6 10:34:31 EDT 2010



On May 6, 2:13 am, Alexander Solla <a... at 2piix.com> wrote:

>
> Yes, but you can do this without the type class magic, and have the
> same degree of safety.
>
>  > data Shape = Square Int | Rectangle Int Int | Circle Float Float |
> etc...
>  > data OpaqueShape = HideShape Shape
>  > area :: OpaqueShape -> Float
>  > area = ...
>
> These constructs are structurally equivalent.  The extra layer of
> abstraction doesn't really add anything in either case.  HideShape (as
> a function) is an isomorphism onto Shapes in both cases.

You're example isn't as easy to extend. If we want to add shapes we
have to edit the original code. We cannot add other shapes at
different places in the code. I prefer the type class magic. It is
more general and generic.


More information about the Haskell-Cafe mailing list