Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: Enum/Bounded question (Henk-Jan van Tuyl)
2. Haskell For C Programmers (Brian Shannon)
3. Re: Parse error. Please, Help me. (Sok H. Chang)
4. Re: Equivalent of inheritance in Haskell (C K Kashyap)
5. Re: Equivalent of inheritance in Haskell (Antoine Latter)
6. Is this scope range problem? (Sok H. Chang)
7. Re: Is this scope range problem? (Luca Toscano)
----------------------------------------------------------------------
Message: 1
Date: Mon, 13 Dec 2010 20:44:52 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
Subject: Re: [Haskell-beginners] Enum/Bounded question
To: beginners <[email protected]>, "Patrick LeBoutillier"
<[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Mon, 13 Dec 2010 18:49:39 +0100, Patrick LeBoutillier
<[email protected]> wrote:
> Hi,
>
> I'm looking for a function to make a list of all the constructors in a
> type that derives both Enum and Bounded, i.e.
>
> enumAll :: (Bounded a, Enum a) => [a]
> enumAll = [minBound .. maxBound]
>
> Does this function exists in the standard modules?
>
>
> Patrick
>
No
Regards,
Henk-Jan van Tuyl
--
http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
--
------------------------------
Message: 2
Date: Mon, 13 Dec 2010 21:55:00 +0000
From: Brian Shannon <[email protected]>
Subject: [Haskell-beginners] Haskell For C Programmers
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
Does anyone have a working link for the Haskell For C Programmers book?
I get a 404 from the link [1] which is on the wiki. [2][3]
Thanks,
Brian
[1] http://www.haskell.org/~pairwise/intro/intro.html
[2] http://www.haskell.org/haskellwiki/Learning_Haskell
[3] http://www.haskell.org/haskellwiki/Meta-tutorial
------------------------------
Message: 3
Date: Tue, 14 Dec 2010 11:20:23 +0900
From: "Sok H. Chang" <[email protected]>
Subject: Re: [Haskell-beginners] Parse error. Please, Help me.
To: Magnus Therning <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Thank you all !!
Have a nice day.
2010/12/13 Magnus Therning <[email protected]>
> On Mon, Dec 13, 2010 at 14:29, Sok H. Chang <[email protected]> wrote:
> > Hello, everyone.
> > I write my second code... but when I compile this, I got an error... (My
> > first code works. of course, at that time, I got an indentation error,
> but I
> > could fix it.)
> > Haskell>ghc --make Temp.hs -o Temp.exe
> > [1 of 1] Compiling Main ( Temp.hs, Temp.o )
> > Temp.hs:7:0: parse error (possibly incorrect indentation)
> >
> > Temp.hs is made using by jEdit on Window XP.
> > I install Haskell Platform.
> > code is ...
> > import System.IO
> > import System.Random
> > let sentenceAry = []
>
> That 'let' isn't necessary.
>
> > main :: IO ()
> > main = do inh <- openFile "c:\\Documents and
> > Settings\\shaegis\\inputFile.txt" ReadMode
> > outh <- openFile "c:\\Documents and Settings\\shaegis\\outputFile.txt"
> > WriteMode
> > mainloop inh outh
> > hClose inh
> > hClose outh
> > mainloop :: Handle -> Handle -> IO ()
> > mainloop inh outh = do ineof <- hIsEOF inh
> > if ineof
> > then do hPutStrLn outh inpStr
> > return ()
> > else do inpStr <- hGetLine inh
> > let sentenceAry = inpStr : []
> > mainloop inh outh
> > Please, help me.
> > Thank you.
> >
> > Sincerely, Sok Chang
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
> >
> >
>
>
>
> --
> Magnus Therning OpenPGP: 0xAB4DFBA4
> email: [email protected] jabber: [email protected]
> twitter: magthe http://therning.org/magnus
>
--
Sok Ha, CHANG
Open Mind Clinic/Academy, 1551-1, Sa-Dong, SangRok-Gu, AnSan-City,
KyongGi-Do
Tel: 031-407-6114
HP: openmind.ac / www.openmind.ac
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/3de074e3/attachment-0001.htm>
------------------------------
Message: 4
Date: Tue, 14 Dec 2010 08:40:56 +0530
From: C K Kashyap <[email protected]>
Subject: Re: [Haskell-beginners] Equivalent of inheritance in Haskell
To: Antoine Latter <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
>
> But there is not a way to easily say (in Haskell) "type A is
> everything that type B is plus these other things here ...". Haskell
> is not an OO language.
This captures what I had in mind. Using compound types seems ok but
I'd still need to do some mechanical stuff if I had to provide a
function that works on the compound type which is actually defined for
a component type.
If I understand you right .. you'd build a 'Man' type and 'Woman' type
by using a 'Person' type. Lets say, there is a function called getName
that is Person -> String
I'd have to mechanically define a function getName :: Man -> String -
that extracts the person inside and calls getName on it - did I
understand it right?
Or would you typically write extract functions that'll return the
components and then the user could call the method on the component?
As in .... getPerson :: Man -> Person ... then call getName on that.
How do you deal with situations like that?
------------------------------
Message: 5
Date: Mon, 13 Dec 2010 22:09:25 -0600
From: Antoine Latter <[email protected]>
Subject: Re: [Haskell-beginners] Equivalent of inheritance in Haskell
To: C K Kashyap <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Mon, Dec 13, 2010 at 9:10 PM, C K Kashyap <[email protected]> wrote:
>>
>> But there is not a way to easily say (in Haskell) "type A is
>> everything that type B is plus these other things here ...". Haskell
>> is not an OO language.
>
> This captures what I had in mind. Using compound types seems ok but
> I'd still need to do some mechanical stuff if I had to provide a
> function that works on the compound type which is actually defined for
> a component type.
>
> If I understand you right .. you'd build a 'Man' type and 'Woman' type
> by using a 'Person' type. Lets say, there is a function called getName
> that is Person -> String
> I'd have to mechanically define a function getName :: Man -> String -
> that extracts the person inside and calls getName on it - did I
> understand it right?
> Or would you typically write extract functions that'll return the
> components and then the user could call the method on the component?
> As in .... getPerson :: Man -> Person ... then call getName on that.
>
> How do you deal with situations like that?
>
Well, in this case I might just have a person type with a 'gender'
field :-) Then I get the polymorphism and code-reuse for free!
But what you're talking about is something that OO-style programming
is particularly aligned towards, and functional programming generally
is not.
One thing people do is use type-classes - this would be a bit like
having 'Car' and 'Truck' implement the same interface. The simple
building blocks would be duplicated, but the complex application-level
functionality could be written against the typeclass.
Another approach is with functional lenses - these are libraries that
aim to make updating complex compound types easier. Off the top of my
head I know of fclabels[1], but I know there are others. If you're
interested in this approach you might be able to email the -cafe
mailing list to ask for more.
Is there a particular problem you're trying to solve? we might be able
to take the conversation in a less speculative direction.
Antoine
[1] http://hackage.haskell.org/package/fclabels
------------------------------
Message: 6
Date: Tue, 14 Dec 2010 15:24:55 +0900
From: "Sok H. Chang" <[email protected]>
Subject: [Haskell-beginners] Is this scope range problem?
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="utf-8"
Hello, everyone.
Thank you so much to previous great answer!
Now, I don't know how can I fix this.
The error is,
Haskell>ghc --make Temp.hs -o Temp.exe
[1 of 1] Compiling Main ( Temp.hs, Temp.o )
Temp.hs:19:27: Not in scope: `inpStr'
The code is,
import System.IO
import System.Random
sentenceAry = []
main :: IO ()
main = do inh <- openFile "c:\\Documents and
Settings\\shaegis\\inputFile.txt" ReadMode
outh <- openFile "c:\\Documents and Settings\\shaegis\\outputFile.txt"
WriteMode
mainloop inh outh
hClose inh
hClose outh
mainloop :: Handle -> Handle -> IO ()
mainloop inh outh = do ineof <- hIsEOF inh
if ineof
then do hPutStrLn outh inpStr
return ()
else do inpStr <- hGetLine inh
let sentenceAry = inpStr : []
mainloop inh outh
I'm try to change like below, but I failed.
mainloop :: Handle -> Handle -> IO ()
mainloop inh outh = do ineof <- hIsEOF inh
if not ineof
then do inpStr <- hGetLine inh
let sentenceAry = inpStr : []
mainloop inh outh
else do hPutStrLn outh inpStr
return ()
I wonder why...
Thank you.
Sincerely, Sok Chang
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20101214/184b8acc/attachment-0001.htm>
------------------------------
Message: 7
Date: Tue, 14 Dec 2010 09:12:52 +0100
From: Luca Toscano <[email protected]>
Subject: Re: [Haskell-beginners] Is this scope range problem?
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=UTF-8; format=flowed
On 12/14/2010 07:24 AM, Sok H. Chang wrote:
> Hello, everyone.
Hello,
I don't understand very well what you're trying to do in your code, but
if it is simply reading from a file and put the output into another file
there is a better way:
import System.IO
import System.Random
sentenceAry = []
main :: IO ()
main = do
inh <- openFile "c:\\Documents and
Settings\\shaegis\\inputFile.txt" ReadMode
outh <- openFile "c:\\Documents and
Settings\\shaegis\\outputFile.txt" WriteMode
mainloop inh outh
hClose inh
hClose outh
mainloop :: Handle -> Handle -> IO ()
mainloop inh outh = do
ineof <- hIsEOF inh
if ineof
then
return ()
else do
inpStr <- hGetLine inh
hPutStrLn outh inpStr
mainloop inh outh
I hope I've understood the problem.. In your code 'inpStr' wasn't in
scope, because you've declared it only into else block..
Luca
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 30, Issue 20
*****************************************