[Haskell-cafe] newbie q about types
jonathanccast at fastmail.fm
Sat Feb 2 01:37:17 EST 2008
On 1 Feb 2008, at 10:30 PM, Logesh Pillay wrote:
> I have a list. Each component is a list with 2 whole numbers.
First off, why? In Haskell (unlike dynamically typed languages like
Python or Perl), if you know you always have two elements, you want a
pair (519432,525806), not a list [519432,525806].
> I want to multiply the second number by the log of the first
> tail ([519432,525806]) * log (head [519432,525806]).
You mean [519432,525806] !! 1 * log ([519432,525806 !! 0)
fst (519432,525806) * log (snd (519432,525806)
or (best of all)
case (519432, 525806) of
(x, y) -> x * log y
or (if you must have a list)
case [519432, 525806] of
[x, y] -> x * log y
> I get the ffg error message:
> No instance for (Floating [t])
This is because
tail :: [t] -> [t]
It doesn't give you a single element; it gives you the whole list!
More information about the Haskell-Cafe