Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Monadic Linear Algebra

Name: Anonymous 2008-11-29 0:45

I'm trying to learn Haskell and I want to create a monad that, when you pass it two matrices, multiplies them, and then takes the inverse. But I cant figure out how, can anyone HELP ME?

Name: Anonymous 2008-11-30 17:59

>>9
“Functor” is an abstract interface for container types. It has a single method, “fmap”, which applies a function f to each element x of the container, replacing it with f(x), but leaves the shape of the container unchanged. In Haskell syntax it looks like this:

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


Lists implement this interface, and fmap on lists is just the usual map function. But fmap also works on Maybe a:

instance Functor Maybe where
    fmap f x = case x of
        Nothing -> Nothing
        Just x  -> Just (f x)


(This definition is more or less obvious if you view Maybe a as a list of at most one element.)

“Monad” is a subclass of Functor, adding two methods: “return”, which wraps a single element in a container, and “join”, which turns a container of containers into a plain container, collapsing some of the intermediate structure. Here are a few sample definitions:

-- Maybe
return :: a -> Maybe a
return x = Just x

join :: Maybe (Maybe a) -> Maybe a
join (Just (Just x)) = Just x
join _ = Nothing

-- Lists
return :: a -> [a]
return x = [x]

join :: [[a]] -> [a]
join = concat

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List