[Haskell-cafe] Re: Implementing fixed-sized vectors (using datatype algebra?)

Alfonso Acosta alfonso.acosta at gmail.com
Tue Feb 19 18:39:43 EST 2008


2008/2/19 Wolfgang Jeltsch <g9ks157k at acme.softbase.org>:
> Attached is just a quickly hacked Boolean module.  Nothing very special.  I'd
> be happy if you could prettify this (choose better names, add documentation,
> etc.).  Thanks for any effort.

Thanks to you for the module. I have a few questions though.

Why are the value-level reflecting functionsimplemented as type-class
methods? It makes the code more verbose and I don't see any advantage
compared to simply defining a function per class. Let me show you an
example:

This is your implementation of Not:

    class (Boolean boolean, Boolean boolean') =>
          Not boolean boolean' | boolean -> boolean', boolean' -> boolean where
        not :: boolean -> boolean'

    instance Not False True where
        not _ = true

    instance Not True False where
        not _ = false

This is how I would do it:

    class (Boolean boolean, Boolean boolean') =>
          Not boolean boolean' | boolean -> boolean', boolean' -> boolean where

    instance Not False True
    instance Not True False

   not :: Not a b => a -> b
   not = undefined



Furthermore, why did you choose to use Boolean instead of simply Bool?


Cheers,

Fons


More information about the Haskell-Cafe mailing list