[Haskell-cafe] Re: [Haskell] Re: Help : A problem with IO

2008-12-15 Thread wman
you probably got it pointed out in haskell-beginners, but in case not:

On Thu, Nov 27, 2008 at 7:10 PM, abdullah abdul Khadir 
abdullah.ak2...@gmail.com wrote:

 a) I need to put a do after else for more than one instruction (?)


No, the do thingy is a syntactic sugar for chaining warm, fuzzy (the
preffered wannabe-joke-term for the presumably scary term monads/monadic)
operations.

it allows you to write in classical imperative/sequential style instead of
chaining operations manually (using the  and = operators, which the do
notation translates into anyway). lookup some monad tutorials/docs.

you are right in that if there is only one operation, no transformation is
needed, so the do is unnecessary.
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell] Re: Help : A problem with IO

2008-11-27 Thread abdullah abdul Khadir
Thanks all,
I got it working finally. What did i learn ?
a) I need to put a do after else for more than one instruction (?)
b) All similar type of questions are to be redirected to haskell-beginner
and haskell-cafe

Points noted.
Thank you once again,
Abdullah Abdul Khadir



On Wed, Nov 26, 2008 at 10:56 PM, wman [EMAIL PROTECTED] wrote:

 if it should really read whole line, it must try to somehow chain the
 values into the string / list of chars (using (:) )

 getMyLine :: IO [Char]
 getMyLine =  do
   c - getChar
   if (c == '\n')
 then return  -- imho [] looks nicer ;-)
 else do
   rest - getMyLine
   return $ c : rest

 -- or

 getMyLine :: IO [Char]
 getMyLine =  do
   c - getChar
   if (c == '\n')
 then return  -- imho [] looks nicer ;-)
 else getMyLine = return . (c:)

 -- or even shorter and still equivalent ;-)

 getMyLine :: IO [Char]
 getMyLine =  getChar = (\c - if (c == '\n') then return [] else fmap
 (c:) getMyLine)



 2008/11/26 abdullah abdul Khadir [EMAIL PROTECTED]

 Hi,

 The function getMyLine written by me is intended for getting a
 complete string from the standard input.

 import IO

 getMyLine :: IO [Char]
 getMyLine =  do
 c - getChar
 if(c == '\n')
 then return 
 elsecs - getMyLine
 return [c]

 However I keep getting the following error:

 io.hs:14:2: Parse error in pattern
 Failed, modules loaded: none.

 I fail to understand what the error is. I tried out various things
 such as changing the alignment and so on to no avail. The following program,
 however, compiled successfully though it has the same structure as the
 previous program.

 checkd :: IO Bool
 checkd = do
 c - getChar
 if(c=='d')
 thenreturn True
 elsereturn False

 Prelude :load ./io.hs
 [1 of 1] Compiling Main ( io.hs, interpreted )
 Ok, modules loaded: Main.
 *Main checkd
 d
 True


 ___
 Haskell mailing list
 Haskell@haskell.org
 http://www.haskell.org/mailman/listinfo/haskell



___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


[Haskell] Re: Help : A problem with IO

2008-11-26 Thread abdullah abdul Khadir
Hi,

The function getMyLine written by me is intended for getting a complete
string from the standard input.

import IO

getMyLine :: IO [Char]
getMyLine =  do
c - getChar
if(c == '\n')
then return 
elsecs - getMyLine
return [c]

However I keep getting the following error:

io.hs:14:2: Parse error in pattern
Failed, modules loaded: none.

I fail to understand what the error is. I tried out various things
such as changing the alignment and so on to no avail. The following program,
however, compiled successfully though it has the same structure as the
previous program.

checkd :: IO Bool
checkd = do
c - getChar
if(c=='d')
thenreturn True
elsereturn False

Prelude :load ./io.hs
[1 of 1] Compiling Main ( io.hs, interpreted )
Ok, modules loaded: Main.
*Main checkd
d
True
___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Re: Help : A problem with IO

2008-11-26 Thread Axel Simon
Hi Abdullah,

On Wed, 2008-11-26 at 21:48 +0530, abdullah abdul Khadir wrote:
 Hi,
 
 The function getMyLine written by me is intended for getting a
 complete string from the standard input. 
 
 import IO 
 
 getMyLine :: IO [Char]
 getMyLine =  do
 c - getChar
 if(c == '\n')
 then return 
 elsecs - getMyLine
 return [c]

a) you forgot a 'do' after 'else'
b) your email would be answered quicker on haskell-beginners or
haskell-cafe since haskell is mainly used for announcements.

Axel.


___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


Re: [Haskell] Re: Help : A problem with IO

2008-11-26 Thread Chris Eidhof

On 26 nov 2008, at 17:18, abdullah abdul Khadir wrote:


Hi,

The function getMyLine written by me is intended for getting a  
complete string from the standard input.


import IO

getMyLine :: IO [Char]
getMyLine =  do
c - getChar
if(c == '\n')
then return 
elsecs - getMyLine
return [c]

However I keep getting the following error:

io.hs:14:2: Parse error in pattern
Failed, modules loaded: none.

I fail to understand what the error is. I tried out various  
things such as changing the alignment and so on to no avail. The  
following program, however, compiled successfully though it has the  
same structure as the previous program.


The else should be replaced by else do. Probably you'll also want  
the last line to be return (c:cs).


By the way, questions like these might be more appropriate on haskell- 
beginners or haskell-cafe.


-chris




checkd :: IO Bool
checkd = do
c - getChar
if(c=='d')
thenreturn True
elsereturn False

Prelude :load ./io.hs
[1 of 1] Compiling Main ( io.hs, interpreted )
Ok, modules loaded: Main.
*Main checkd
d
True

___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell


___
Haskell mailing list
Haskell@haskell.org
http://www.haskell.org/mailman/listinfo/haskell