[Haskell-cafe] Re: GADT and typeclasses [was: Language extensions]

apfelmus apfelmus at quantentunnel.de
Mon May 28 06:02:51 EDT 2007


oleg at pobox.com wrote:
> Philippa Cowderoy wrote:
>> For example, GADTs let you implement monads as interpreters by defining a
>> datatype representing the abstract syntax tree that describes a
>> computation - you can't get this to type without at a minimum existential
>> types and for many monad operations you need the full power of GADTs to
>> declare a corresponding constructor.
> 
> I'm yet to see the example of that need. I have seen the examples that
> the need for GADT was _claimed_ -- but then it turns out the example
> is implementable without GADT after all. Here are a few such
> examples: implementing State monad in a free term algebra
> 
> 	Initial (term) algebra for a state monad
> 	http://www.haskell.org/pipermail/haskell-cafe/2005-January/008241.html

Note that this argument can be extended to deny the need of any "sum of
products" construction. In other words, even declarations like

   data Color = Red | Green | Blue

can be implemented with typeclasses and without |. Thus, we don't need
them... :)

The other point is that using existentials for sums has a problem: I
think it's impossible to implement many functions that take multiple
arguments of the existential type. The example that comes to mind first is

 (==) :: Statte s a -> Statte s a -> Bool

How to implement this? (Besides the fact that it's impossible to
implement due to the fact that we'd need an equality on function types,
but let's use a different example whose constructors don't store
function types.)

Regards,
apfelmus



More information about the Haskell-Cafe mailing list