Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
        [email protected]

You can reach the person managing the list at
        [email protected]

When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."


Today's Topics:

   1. Re:  Handling a MonadError (Stephen Tetley)
   2. Re:  Handling a MonadError (Stephen Tetley)
   3.  Please critique my first library (Gideon)
   4. Re:  How to avoid repeating code (Daniel Fischer)


----------------------------------------------------------------------

Message: 1
Date: Mon, 30 May 2011 22:17:00 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Handling a MonadError
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 30 May 2011 20:35, Christopher Howard
<[email protected]> wrote:

> class (Monad m) => MonadError e m | m -> e where
> ? ?throwError :: e -> m a
> ? ?catchError :: m a -> (e -> m a) -> m a
>
> More specifically: Why is there a pipe symbol followed by what looks
> like a function definition in the "class" line?

It is a functional dependency.

Generally you can read it as "m uniquely determines e".



------------------------------

Message: 2
Date: Mon, 30 May 2011 22:23:11 +0100
From: Stephen Tetley <[email protected]>
Subject: Re: [Haskell-beginners] Handling a MonadError
Cc: Haskell Beginners <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

On 30 May 2011 22:17, Stephen Tetley <[email protected]> wrote:
> On 30 May 2011 20:35, Christopher Howard
>> More specifically: Why is there a pipe symbol followed by what looks
>> like a function definition in the "class" line?
>
> It is a functional dependency.
>
> Generally you can read it as "m uniquely determines e".
>

The simplest instance seems to be this one:

instance (Error e) => MonadError e (Either e) where
    throwError             = Left
    Left  l `catchError` h = h l
    Right r `catchError` _ = Right r

The functional dependency tells GHC that the error parameter 'e' is
the same type variable 'e' that is in monad parameter '(Either e)'



------------------------------

Message: 3
Date: Tue, 31 May 2011 10:36:58 +0300
From: Gideon <[email protected]>
Subject: [Haskell-beginners] Please critique my first library
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1

I've written a modest data binding library for haskell GUIs; the code
is at http://code.accursoft.com/binding/. binding-core exposes
functionality for binding IO objects to mutable variables and lists.
bindnig-gtk and binding-wx are wrappers for Gtk2Hs and WxHaskell
respectively.

Examples of how to use these can be found in the tests directory of
binding-core, and the demo directories of the GUI wrappers.

Thank you!



------------------------------

Message: 4
Date: Tue, 31 May 2011 10:23:48 +0200
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] How to avoid repeating code
To: Federico Mastellone <[email protected]>, [email protected]
Message-ID: <[email protected]>
Content-Type: Text/Plain;  charset="utf-8"

On Monday 30 May 2011 21:44:32, Federico Mastellone wrote:
> I've been looking at the Edison package, it has a big class
> hierarchy without default implementations using functional dependencies
> and I found tidier doing something similar with associated types.

Doesn't surprise me.

> 
> Writing default implementations continues to be troublesome.
> 
> Here is an example adding an elems function to the Collection class
>  elems :: c -> [Elem c]
> I can't write on the MultiMapClass class a default implementation
> for getValueList like this
>  getValueList :: Key m -> m -> [Value m]
>  getValueList k m = elems $ getValues k m
> because elems returns
>  [Elem (Coll m)]
> so I have to write
>  getValueList :: Key m -> m -> [Elem (Coll m)]
> and it doesn't matter that this means the same for the implementations I
> have
>  Elem (Set.Set a) ~ Value (MultiMap k v)
> and
>  Elem IntSet.IntSet ~ Value IntMultiMap

Well, I guess you'd want to have Value m ~ Elem (Coll m) in all cases, so 
you could remove the Value type completely and replace (Value m) with (Elem 
(Coll m)) in all places (although it would be nicer to be able to use the 
shorter Value m, I'm not sure whether you can write such an alias,
type (constraints?) => Value m = Elem (Coll m), be it at the top level or 
in the class declaration, but you could add the equality constraint to the 
class context).

> 
> Now when using classes like this you need to need to think twice when
> coding! Typing becomes much more complicated.
> 
> I don't know if I am too object oriented or is the lack of IDEs but

That could be part of it. Trying to write your code in the OO way in 
Haskell tends to be painful, you have to look at things from a different 
angle to play to the language's strengths.

> reusing code, grouping together code with similarities and managing
> many modules is not easy with Haskell.

Common opinion among Haskellers seems to be that it's easier in Haskell 
than in (most) other languages (massive selection bias, of course).

> Things that I found essential to
> write large programs. I'm starting to think that the easiest way of
> writing generic and reusable code with Haskell is writing a Haskell
> parser and code generator in Haskell.

Considering how easy writing such is in Haskell, that could in fact be not 
too much of an exaggeration :)



------------------------------

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


End of Beginners Digest, Vol 35, Issue 61
*****************************************

Reply via email to