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
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
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
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
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
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*
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