[Haskell-cafe] weird

2005-07-16 Thread wenduan
The following function which converts a number represents a sum of money in pence didn't work as expected and the result didn't make any sense to me: penceToString :: Price -> String penceToString p = let str = show p len = length str in if len ==1 then "0.0" ++ str else

[Haskell-cafe] weired

2005-07-16 Thread wenduan
The following function which converts a number represents a sum of money in pence didn't work as expected and the result didn't make any sense to me: penceToString :: Price -> String penceToString p = let str = show p len = length str in if len ==1 then "0.0" ++ str else

[Haskell-cafe] a simple function

2005-07-12 Thread wenduan
Anyone please tell me what is wrong with the function: isEmpty ::[a]->Bool isEmpty xs | xs == [] = True |otherwise =False When I tried to load it into the interpreter,it says the following: Could not deduce (Eq a) from the context () arising from use of `==' at mylab

[Haskell-cafe] polymorphic type

2005-07-06 Thread wenduan
Dear all, Suppose we have defined two functions as below: case :: (a -> c,b -> c) -> Either a b -> c case (f, g) (Left x) = f x case (f, g) (Right x) = g x plus :: (a -> b, c -> d) -> Either a b -> Either c d plus (f, g) = case(Left.f, Right.g) My question is regarding to the function signatur

Re: [Haskell-cafe] pair (f,g) x = (f x, g x)?

2005-07-02 Thread wenduan
snd) (2,'a') ==> ((square . fst) (2,'a'), (Char.toUpper . snd) (2,'a')) ==> ( square (fst(2,'a')), Char.toUpper (snd(2,'a')) ) ==> ( square 2 , Char.toUpper 'a' ) ==> (4,'A') - marc Am Samstag, 2. Juli 2005 08:3

[Haskell-cafe] pair (f,g) x = (f x, g x)?

2005-07-02 Thread wenduan
I came across a haskell function on a book defined as following: pair :: (a -> b,a -> c) -> a -> (b,c) pair (f,g) x = (f x,g x) I thought x would only math a single argument like 'a', 1, etc,but it turned out that it would match something else, for example, a pair as below: square x = x*

[Haskell-cafe] basic haskell question

2005-05-22 Thread wenduan
hi, Anybody could please tell me that in the following two expressions what value does the [] take? foldl (/) 3 [] foldr (/) 3 [] when both of them are evaluated I got 3.0,but I thought I could get nothing out of there,cause its an empty list,does Haskell assume any default value for a empty