From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <20090715222758.28371a78.eekee57@fastmail.fm> References: <7d3530220907151000s60671d2gfdb18cdf12c55097@mail.gmail.com> <0009e18319f5c60dc890463505286c1c@quintile.net> <3e1162e60907151159g5b031e99k2ad8171c9c268392@mail.gmail.com> <9ab217670907151314n4e5c5855oda60cc527bb83422@mail.gmail.com> <56a297000907151342x334e7793ubfedb791a62f2bd8@mail.gmail.com> <3e1162e60907151351n1e88a15ue70da5cdd83317b4@mail.gmail.com> <20090715222758.28371a78.eekee57@fastmail.fm> Date: Wed, 15 Jul 2009 18:31:06 -0500 Message-ID: From: Jason Catena To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/alternative; boundary=0016364ecd80013c1f046ec6f301 Subject: Re: [9fans] Why does Acme only show text? Topicbox-Message-UUID: 22c651a6-ead5-11e9-9d60-3106f5b1d025 --0016364ecd80013c1f046ec6f301 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Real World Haskell ch4 pp71-72 >> do x <- foo >> y <- bar >> >> the y <- bar must be directly under the x on the previous line or it's a >> syntax error, and the error you get from GHC is "the last statement of a do >> construct must be an expression" > > Huh, so this Haskell syntax actually prevents you from indenting something that would be indented in any other language. Okay... I didn't read it like this. The x and y must be lined up because they are both part of the same set of do-statements. If the y line was a standalone statement, then it could be indented as shown in this code segment. But in that case there's no need for a do, since the point of do is to order statements in sequential time. the following is a complete Haskell program, using do, which passes through its input file to an output file. The > specifies code lines, other lines are considered comments. (I hope gmail preserves the spacing.) Real World Haskell ch4 pp71-72 > import System.Environment (getArgs) > > interactWith function inputFile outputFile = do > input <- readFile inputFile > writeFile outputFile (function input) > > main = mainWith myFunction > where mainWith function = do > args <- getArgs > case args of > [input,output] -> interactWith function input output > _ -> putStrLn "error: need exactly two arguments" Replace id with any function (of the same type) to process the data. > myFunction = id --0016364ecd80013c1f046ec6f301 Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Real World Haskell ch4 pp71-72
>> do x <- foo
>> y <= ;- bar
>>
>> the y <- bar must be directly under the x= on the previous line or it's a
>> syntax error, and the error= you get from GHC is "the last statement of a do
>> construct must be an expression"
>
> Huh, so this= Haskell syntax actually prevents you from indenting something that would b= e indented in any other language. Okay...

I didn't read it like = this. =A0The x and y must be lined up because they are both part of the sam= e set of do-statements. =A0If the y line was a standalone statement, then i= t could be indented as shown in this code segment. =A0But in that case ther= e's no need for a do, since the point of do is to order statements in s= equential time.

the following is a complete Haskell program, using do, which passes thr= ough its input file to an output file. =A0The > specifies code lines, ot= her lines are considered comments. (I hope gmail preserves the spacing.)

Real World Haskell ch4 pp71-72<= /div>

> import System.Environment (getArgs)
>
> interactWith function inputFile outputFile =3D do<= /div>
> =A0 = input <- readFile inputFile
> =A0 writeFile outputFile (fun= ction input)
>
> main =3D mainWith myFunction
> =A0 = where mainWith function =3D do
> =A0 =A0 =A0 =A0 =A0 args <= - getArgs
> =A0 = =A0 =A0 =A0 =A0 case args of
> =A0 =A0 =A0 =A0 =A0 =A0 [input,= output] -> interactWith function input output
> =A0 = =A0 =A0 =A0 =A0 =A0 _ -> putStrLn "error: need exactly two argument= s"

Replace id with any function (of the same type)
to proces= s the data.

> myFunction =3D id


--0016364ecd80013c1f046ec6f301--