[Haskell-beginners] help with IO guards

Julian Birch julian.birch at gmail.com
Thu Jan 15 21:27:19 UTC 2015


Not really, for the same reason: a guard needs a Bool, and you can't get a
Bool from IO Bool.

On Thursday, January 15, 2015, Miro Karpis <miroslav.karpis at gmail.com>
wrote:

> many thanks,....but then I unfortunately don't understand how can I fix my
> initial problem:
>
> to use IO check in guards - is that possible?
>
> Regards,
> Miro
>
> On Thu, Jan 15, 2015 at 10:12 PM, Julian Birch <julian.birch at gmail.com
> <javascript:_e(%7B%7D,'cvml','julian.birch at gmail.com');>> wrote:
>
>> Going back to an earlier question: a monad is a bit like a roach motel.
>> You can check in but you can't leave. (This isn't true of every Monad, but
>> the point is there's no guarantees.) In particular, you can't go from IO
>> String to String _at all_. But you can, through Functor, pass it to a
>> function that takes a plain String. And through Monad, you can turn IO
>> (IO String) back to IO String.
>>
>> Hope this helps.
>>
>>
>> On Thursday, January 15, 2015, Marcin Mrotek <marcin.jan.mrotek at gmail.com
>> <javascript:_e(%7B%7D,'cvml','marcin.jan.mrotek at gmail.com');>> wrote:
>>
>>> Hello,
>>>
>>> A list ([]) is also a monad, and a String is defined as a list of
>>> characters ([Char]). So in your example, it's as if you were trying to
>>> use (>>=) operator on two different monads ([] and IO), which is
>>> impossible. To make a pure value a monadic value, you need to use
>>> return:
>>>
>>> g = readLn >>= (\a -> return (f a))
>>>
>>> which is equivalent to composing f with return:
>>>
>>> g = readLn >>= return.f
>>>
>>> Regards,
>>> Marcin
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>>
>> --
>> Sent from an iPhone, please excuse brevity and typos.
>>
>
>

-- 
Sent from an iPhone, please excuse brevity and typos.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20150115/b656f21c/attachment.html>


More information about the Beginners mailing list