[Haskell-beginners] More direct binding of IO result
aditya siram
aditya.siram at gmail.com
Sun May 15 14:00:48 CEST 2011
Crap! You're right, should've tried it out. Sorry Christopher! The second
approach does work though.
-deech
On Sun, May 15, 2011 at 6:58 AM, Michael Snoyman <michael at snoyman.com>wrote:
>
>
> On Sun, May 15, 2011 at 2:56 PM, aditya siram <aditya.siram at gmail.com>wrote:
>
>> You can also try the applicative way:
>> (<$>) :: (a -> b) -> f a -> f b
>>
>> import Control.Applicative
>> -- Think of the <$> as a monadic version of $
>> main = putStrLn <$> readFile "contents.txt"
>>
>> Actually, <$> is just a synonym for fmap, so this will have the same
> problems as the fmap approach.
>
> Michael
>
>
>> Or if you want to chain the functions and not worry about the
>> "contents.txt" argument:
>>
>> import Control.Monad
>> main= (readFile >=> putStrLn) "contents.txt"
>>
>> -deech
>>
>> On Sun, May 15, 2011 at 1:27 AM, Christopher Howard <
>> christopher.howard at frigidcode.com> wrote:
>>
>>> I understand that one can bind the unwrapped results of IO functions to
>>> variables, and pass them to functions, like so:
>>>
>>> main = do filecontents <- readFile "data.txt"
>>> putStrLn filecontents
>>>
>>> But does the syntax allow you to cut out the middle man, so to speak,
>>> and bind the results directly to the parameter? Like
>>>
>>> -- Tried this and it didn't work.
>>> main = do putStrLn (<- readFile "data.txt")
>>>
>>> --
>>> frigidcode.com
>>> theologia.indicium.us
>>>
>>> _______________________________________________
>>> Beginners mailing list
>>> Beginners at haskell.org
>>> http://www.haskell.org/mailman/listinfo/beginners
>>>
>>
>>
>> _______________________________________________
>> Beginners mailing list
>> Beginners at haskell.org
>> http://www.haskell.org/mailman/listinfo/beginners
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20110515/a5d6d6fa/attachment-0001.htm>
More information about the Beginners
mailing list