[Haskell-beginners] Doing IO in terms of Arrow

Ertugrul Soeylemez es at ertes.de
Mon Jun 27 18:38:34 CEST 2011


Haisheng Wu <freizl at gmail.com> wrote:

>   I'm wondering if it is possible doing IO in terms of Arrow.
>   I got a function search all files under directory recursively and
> I'd like to refartoring using Arrow terms.

Yes, it's possible using Kleisli, but it's not very convenient, because
you need the Kleisli wrapper around everything.  Also usually there is
really little reason to do that, because monads are more expressive.
For example they allow you to encode computations with only outputs
directly, without wrapping them in a computation, which takes a stub
argument.


>   I tried to define a function like below but failed.
>   isDirExist = Kleisli doesDirectoryExist
>
>   Do I need to define a instance for IO to be Arrow? Or is there any
> existing solutions?

No, the needed instances are already there, but you need to change your
type signatures:

    myGetFilesInDir :: Kleisli FilePath [FilePath]


Greets,
Ertugrul


-- 
nightmare = unsafePerformIO (getWrongWife >>= sex)
http://ertes.de/





More information about the Beginners mailing list