[Haskell-cafe] Over general types are too easy to make.

Ketil Malde ketil at malde.org
Sun Sep 2 15:25:37 CEST 2012

<timothyhobbs at seznam.cz> writes:

> case largeMultiConstructorTypedValue of
>    Foo{blah=blah,brg=brg} -> .... Some large block...
>    Bar{lolz=lolz,foofoo=foofoo} -> ...Another large block...
>    Frog{legs=legs,heads=heads} -> Yet another large block...
> Where the obvious re-factor is:

> case largeMultiConstructorTypedValue of
>    foo at Foo -> processFoo foo
>    bar at Bar -> processBar bar
>    frog at Frog -> processFrog frog

Hm - is that really so obvious?  To me, it seems like the definition
of processFoo will typically be:

  processFoo (Foo blah brg) = ...

deconstructing the Foo again.  If the Foo is very big, this might be
a good solution, but in many cases, I expect you can do:

  case largeMultiConstructorTypedValue of
     Foo {blah=blah,brg=brg} -> processBlahBrg blah brg

and this would make the type more specific.

If I haven't seen further, it is by standing in the footprints of giants

More information about the Haskell-Cafe mailing list