[Haskell-cafe] On the verge of ... giving up!
Andrew Coppin
andrewcoppin at btinternet.com
Sun Oct 14 10:20:47 EDT 2007
Vimal wrote:
> IO isnt the only problem. Monads + how to define your own Monads etc.
> Since Monad's arent just for IO, where else could it be used? (e.g.
> Stateful functions), but is that it? Is it possible for me to come
> up with an instance of a Monad to solve _my_ problem? Thats the kind
> of question I would like to answer :)
>
I/O is a monad. Actually, there's another one called STM (for doing
"transactional" modifications). And there are various ones for doing
"stateful" stuff (e.g., incrimentally building a solution or something).
Then there's the Maybe monad (for operations which sometimes fail).
Lists are a monad (for operations that yield multiple results).
Parsers are a celebrated example of monads - although the most efficient
ones use something called "arrows". (These are like monads, but even
more abstract. If you enjoy making your head hurt...)
There is also an entire zoo of other monads out there. There's a CPS
monad (for writing unmaintainable code), many graphics libraries have a
"drawing monad"... the list goes on.
Is there any merit in you writing your own monad? Well, if it's doing
something similar to existing monads, then maybe. (Note that there are
such things as "monad transformers", which allow you to merge multiple
monads together into a giant, all-powerful monad. So, if you wanted a
stateful parser that does I/O, you could use transformers to mix those
exact features together - no coding required.)
>> I would try number 2 first. IO in Haskell can be tricky, especially
>> while you are learning all the other bits of the language at the same
>> time. Network stuff is also not as well developed in terms of
>> libraries as something like Python - but something like HappS should
>> be able to do a spoj clone easily enough. A better choice for an
>> initial IO application might be something like "du", then moving to an
>> online judge system later on.
>>
>
> You are probably right. Mimicking *nix tools might be great fun to start
> off with :)
>
Uh... think it's been done already. ;-)
Still, you could try it yourself and see what you get - and then marvel
at how others have done it in half the code. :-}
More information about the Haskell-Cafe
mailing list