Why can't I map a function that is multiplied by Fractional to a Nums list?

I want to make a list of numbers every 0.1from -150to 150.

To do this, I created a list and then tried to display lambda fractional multiplication on it, for example:

let indices = [-1500,-1499..1500]
let grid = map (\x -> 0.1 *x) indices

This causes ghci to spit out an error.

On the other hand, both of these functions work fine:

let a = 0.1*2

and

let grid = map (\x -> 2 *x) indices

What's going on here? Why does multiplication of a number by a fractional number occur only when applied to a list with a map?

EDIT: The error I get is:

No instance for (Fractional Integer)
  arising from the literal `0.1'
Possible fix: add an instance declaration for (Fractional Integer)
In the first argument of `(*)', namely `0.1'
In the expression: 0.1 * x
In the first argument of `map', namely `(\ x -> 0.1 * x)'
+5
source share
4 answers

" ". GHC indices [Integer] Num a => a. , indices :: [Float], , .

( ), indices : let indices a = [-1500, -1499..1500], (Enum t, Num t) => a -> [t]. a , . map f (indices whatever). . Haskell Wiki .

+10

.

indices, Num, , Integer, 0.1, 0.1 .

:

let indices :: (Enum a, Num a) => [a]; indices = [-1500,-1499..1500]

.

haskell, : http://www.haskell.org/haskellwiki/Monomorphism_restriction

+8
let grid = map (\x -> 0.1 * (fromInteger x)) indices

- [-150.0, -149.9, -149.8, -149.70000000000002, -149.6, -149.5...]

+1

let indices = [-1500,-1499..1500]

let grid = map ( \x -> x /10 ) indices

0,1

. " "

-1

All Articles