[Haskell-cafe] Re: please help me to find errors from my first app

2008-08-10 Thread Changying Li
thanks. I know how to do it. I should treat it as a stream. 
-- 

Thanks  Regards

Changying Li

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


Re: please help me

2002-04-06 Thread Michal Wallace

On Sun, 7 Apr 2002, Eric wrote:

| Hi there, I am a beginner a haskell,and I have some
| difficulty in dealing with an assignment that is to
| translate a string representation of a list of
| appointments into a list of appointments.  For example:

[requirements snipped] 

| How can I finish the requirement make use of library
| functions such as words, unwords, lines and break.

Hey Leo,

Well, I'm just learning haskell too, but I decided to give
this a shot. I think I solved the main problem, but I did
hit a few snags of my own so I can't be sure. Here goes:

Basically, I defined appointment as a single type...  But
I couldn't figure out how to print that type. So I can't
really test what I've done, other than I know it
compiles. :) Can someone show me how to fill in show down
here? )

 module Main where
 
 data Appt = Appt (Bool, Int, Int, String)
 instance Show Appt where
show x = ???


I then used liness and words to break the multi-line string
into a list of lists of words:

 strToApps :: String - [Appt]
 strToApps x = map lineToApp (lines x)
 lineToApp x = wordsToApp (words x)


Since the starting ! was optional, the structure of the
list could go in two directions here:

 wordsToApp :: [String] - Appt
 wordsToApp ws | head ws == ! = mkAppt True (tail ws)
   | otherwise  = mkAppt False (ws)


Now it's just a matter of parsing the rest of the line.  For
simplicity's sake, I took the liberty of assuming you always
used the same number of digits for the hours, so I didn't
have to search for the -:

 mkAppt :: Bool - [String] - Appt
 mkAppt isImp (w:ws) = Appt (isImp, start, done, note)
 where (hs, hd) = splitAt 3 w  -- assumes zero-padded (eg 01-03)
   start = atoi hs
   done = atoi hd
   note = foldr1 concat ws
   concat a b = a ++   ++ b



That atoi function came from working through the exercises
in Rex Pages online book ( http://www.cs.ou.edu/cs1323h/textbook/haskell.shtml )

 horner str = foldr1 op (reverse str)
 where op d s = d + (10 * s)
 atoi str = horner [digitToInt d | d - str]


Then I defined a main function:

 -- I wonder what a refec is. :)
 main = do print $ strToApps ! 10-11 lecture\n12-13 lunch at the refec :(


... And that's it! I think it would work if I could figure
out how to print Appt objects (or whatever you call them in
haskell). Meanwhile, I get this because of the way I defined
show:

Main main
[???,???]

Cheers,

- Michal   http://www.sabren.net/   [EMAIL PROTECTED] 

Give your ideas the perfect home: http://www.cornerhost.com/
 cvs - weblogs - php - linux shell - perl/python/cgi - java


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Please help me

2001-02-08 Thread Ashley Yakeley

At 2001-02-08 13:49, FAIZAN RAZA wrote:

write a Haskell
function cartesianProduct which when given three lists  (to represent three
sets) of integers returns a list of lists of ordered triples.

That's easy. Just define 'product' as a function that finds the cartesian 
product of any number of lists, and then once you've done that you can 
apply it to make the special case of three items like this:

cartesianProduct a b c = product [a,b,c]

At least, that's how I would do it.

-- 
Ashley Yakeley, Seattle WA


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



Re: Please help me

2001-02-08 Thread Ashley Yakeley

At 2001-02-08 02:04, Ashley Yakeley wrote:

That's easy. Just define 'product' as a function that finds the cartesian 
product of any number of lists, and then once you've done that you can 
apply it to make the special case of three items like this:

cartesianProduct a b c = product [a,b,c]

At least, that's how I would do it.

eesh, 'product' is something else in the Prelude. Better call it 
'cartprod' or something.

-- 
Ashley Yakeley, Seattle WA


___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe



RE: Please help me

2001-02-08 Thread Chris Angus

Faizan,

A clue is to use list comprehensions (which are very like ZF set notation)

First think how you would define a cartesian product in set notation

X x Y x Z = {(x,y,z) | ...}

and then think how this is written in list comprehension notation

Chris

 -Original Message-
 From: FAIZAN RAZA [mailto:[EMAIL PROTECTED]]
 Sent: 08 February 2001 13:49
 To: [EMAIL PROTECTED]
 Subject: Please help me
 
 
 Hello
 
 
 Please help me to solve this questions
 
 
 Question
 
 Cartesian Product of three sets, written as X x Y x Z is 
 defined as the set
 of all ordered triples such that the first element is a 
 member of X, the
 second is member of Y, and the thrid member of set Z. write a Haskell
 function cartesianProduct which when given three lists  (to 
 represent three
 sets) of integers returns a list of lists of ordered triples.
 
 For examples,  cartesianProduct [1,3][2,4][5,6] returns
 [[1,2,5],[1,2,6],[1,4,5],[1,4,6],[3,2,5],[3,2,6],[3,4,5],[3,4,6]]
 
 
 
 Please send me reply as soon as possible
 
 Ok
 
 I wish you all the best of luck
 
 
 
 ___
 Haskell-Cafe mailing list
 [EMAIL PROTECTED]
 http://www.haskell.org/mailman/listinfo/haskell-cafe
 

___
Haskell-Cafe mailing list
[EMAIL PROTECTED]
http://www.haskell.org/mailman/listinfo/haskell-cafe