[Haskell-cafe] Factoring into type classes

Derek Elkins derek.a.elkins at gmail.com
Mon Jan 19 15:40:19 EST 2009


On Mon, 2009-01-19 at 21:18 +0100, Alberto G. Corona wrote:
> This is one of the shortcomings of haskell not to mention other
> programming languages. Mathemathicist would find it very annoying.
> 
> 
> Instead of 
> 
> 
> instance Monoid Integer where
>     mappend = (+)
>     mempty = 0
> 
> instance Monoid Integer where
>     mappend = (*)
>     mempty = 1
> 
> 
> which is not legal and the workaround
> 
> Num a => Monoid (Sum a)
> Num a => Monoid (Product a)
> 
> wich is cumbersome
> A mathematician  would say something like:
> instance Monoid Integer with operation + where
>     mappend = (+)
>     mempty = 0
> and
> 
> instance Monoid Integer with operation * where
> 
>     mappend = (*)
>     mempty = 1

Check out the OBJ family of languages, particularly OBJ3 and (I think)
Maude.

> 
> 
> But talking about shortcomings, personally I prefer to implement first
> a form of assertion that permits the checking of the  class properties
> automatically for each new instance. 
>  
> This is far more important in práctical terms.
> 
> 
> 
> 2009/1/19 Thomas DuBuisson <thomas.dubuisson at gmail.com>
>         2009/1/19 Luke Palmer <lrpalmer at gmail.com>:
>         
>         
>         > On Mon, Jan 19, 2009 at 3:58 AM, Patai Gergely
>         <patai_gergely at fastmail.fm>
>         > wrote:
>         >>
>         >> However, there are other type classes that are too general
>         to assign
>         >> such concrete uses to. For instance, if a data structure
>         can have more
>         >> than one meaningful (and useful) Functor or Monoid
>         instance,
>         >
>         > As a side curiosity, I would love to see an example of any
>         data structure
>         > which has more than one Functor instance.  Especially those
>         which have more
>         > than one useful functor instance.
>         > Luke
>         
>         
>         The recent, and great, blog post about moniods [1] discusses
>         the fact
>         that (Num a) could be one of several different monoids and how
>         that
>         was handled.
>         
>         [1]
>         http://sigfpe.blogspot.com/2009/01/haskell-monoids-and-their-uses.html
>         
>         _______________________________________________
>         Haskell-Cafe mailing list
>         Haskell-Cafe at haskell.org
>         http://www.haskell.org/mailman/listinfo/haskell-cafe
>         
> 
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe



More information about the Haskell-Cafe mailing list