In the course of learning to program with monads, I have (so far) just
had two slight problems that I think might concern the basic Haskell
language, and be quite possible to solve in the next version... I
don't know if anybody agrees but anyway:

Using cc.prelude in Gofer 2.30, and ccexamples.gs containing the StateMonad,
I entered the following:

        dincr1  =       (do incr; fetch) `startingWith` 3 -- returns 4

This worked. I then tried to get rid of the `startingWith` 3 to make
it somewhat more useful:

        dincr1b =       do incr; fetch

Gofer then said:

        ERROR "ccx.gs" (line 100): Unresolved top-level overloading
        *** Binding             : dincr1b
        *** Inferred type       : _4 Int Int
        *** Outstanding context : StateMonad _4 Int

It didn't matter that I put in a new function dincr1c using dincr1b so
that its type should be possible to deduce:

        dincr1c = dincr1b `startingWith` 3
        dincr1b = do incr; fetch

Maybe this could be solved by global analysis? 

Looking at the error message I managed to compile the function using
the following declaration:

        dincr1b::       StateMonad a Int=>a Int Int

I would have been really stuck without the informative error message
>from Gofer! But if the compiler can give enough information to me that
I, just learning the type and monad system, can insert this type
declaration rather mechanically, maybe the compiler could do the same
automatically?

Anyway, thinking that this might be the first of several similar
functions that I was going to write, I then tried to write the type
specifications at one place only, with a type synonym:

        type STT = StateMonad a Int=>a Int Int
        dincr1b::       STT

But the STT declaration was not accepted:

        ERROR "ccx.gs" (line 99): Syntax error in input (unexpected `=>)

I saw in the proposed changes for Haskell 1.3 that this syntax with a
context will be allowed for the 'newtype' declaration. Maybe ordinary
type synonyms could be extended to this also?

Or should I really do this in some other way?

Sverker



Reply via email to