On Nov 9, 7:45 am, Ralf Hemmecke <r...@hemmecke.de> wrote:
> And even if the above were possible, I don't see how it would help to
> reuse code. My code above is just a category after all with no default
> implementation.

What might (or might not) be useful is to look at how Functor and
Monad are defined as typeclasses and then implemented in the standard
Haskell prelude:

class  Functor f  where
    fmap              :: (a -> b) -> f a -> f b

class  Monad m  where
    (>>=)  :: m a -> (a -> m b) -> m b
    (>>)   :: m a -> m b -> m b
    return :: a -> m a
    fail   :: String -> m a
        -- Minimal complete definition:
        --      (>>=), return
    m >> k  =  m >>= \_ -> k
    fail s  = error s

and then to go on to see how instances of it are used, perhaps the
simplest is the maybe monad:

instance  Monad Maybe  where
    (Just x) >>= k   =  k x
    Nothing  >>= k   =  Nothing
    return           =  Just
    fail s           =  Nothing

The problem is that I think we are trying to do something different
from Haskell. Haskell is using this mostly as a tool to separate the
pure from the impure code but languages like SPAD don't try to do
that, I think we would be more interested in modelling the
mathematical concept of the monad and perhaps exploring its
relationship to T-algebras? (well that what I'm interested in).

So from the mathematical point of view we may need to keep in mind
that:

1) The above Monad typeclass is not built from the Functor in the way
that a mathematical monads is built from an (endo-)Functor (the above
typeclasses are separate).
2) 'return' above corresponds to what we have been calling 'unit' but
'>>=' does not quite correspond to what we have been calling 'mult'.
They have swapped things around a bit to make it easier to simulate
imperative code.

Martin

-- 
You received this message because you are subscribed to the Google Groups 
"FriCAS - computer algebra system" group.
To post to this group, send email to fricas-devel@googlegroups.com.
To unsubscribe from this group, send email to 
fricas-devel+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/fricas-devel?hl=en.

Reply via email to