Lane’s Blog

Roguestar, Haskell, and Fun

Archive for the ‘Haskell’ Category

MaybeArrow?

without comments

As I’ve found myself repeatedly writing a bit of code that looked vaguely like this:

get :: SomeArrow String (Maybe Thing)

foo :: [Thing] -> FooThing

. . .

getAToZ :: SomeArrow () (Maybe FooThing)
getAToZ = proc () ->
    do m_a <- get -< “a”
       m_b <- get -< “b”
       . . .
       m_z <- get -< “z”
       returnA -<
           do a <- m_a
              b <- m_b
              . . .
              z <- m_z
              return $ foo [a,b . . . z]

It seemed that there would have to be a way to automate this. So I wrote this MaybeArrow (careful, I’m still using 6.8.2 so it’s the old arrows with ‘pure’.). I know that there is already an ErrorArrow. But ErrorArrow as far as I can see requires ArrowChoice, and I’m not doing that. In the MaybeArrow, if an earlier computation throws a Nothing, then later computations are still allowed to perform side effects, although their outputs are snuffed, which is the behavior I want.

I would appreciate any constructive feedback.

If you’re wondering the use case has to do with waiting on several separate pieces of information to arrive from a server and combining them into one output message.

Written by Lane

January 4th, 2009 at 7:16 pm

Posted in Haskell

He Said She Said

without comments

Donald Knuth says: If people do discover nice ways to use the newfangled multithreaded machines, I would expect the discovery to come from people who routinely use literate programming.

This is called Haskell.

Written by Lane

April 27th, 2008 at 8:01 am

Posted in Haskell

Little Things that Bother Me in Haskell

without comments

(++) is basically `mappend`.

(.) is basically `fmap`.

Others?

I’m told that (++) originally was `mappend`, but it was specialized to avoid confusing the newbies. I’m not going to waste bytes arguing with consensus formed before I knew the language existed, but I disagree.

Written by Lane

June 28th, 2007 at 9:55 pm

Posted in Haskell