Hessell type dessignation

I need dessignate types of 2 functions (without using the compiler: t) I just don't know how soudl I read these functions to take the right steps.

f x = map -1 x
f x = map (-1) x

Well, I'm a little confused how he will figure it out

+3
source share
4 answers

A functional application or “empty space operator” has a higher priority than any operator character, so the first line parses as f x = map - (1 x)what is likely to be 1 . p>

, , , (-1) desugars negate 1. , , (+1) desugar, (\x -> x + 1), 1 , map , , .

1 , , Num , .

+4

Haskell Report. Haskell 98.

, "". , , ..

+3

These functions are typeless because they do not introduce validation (you get ridiculous class class restrictions). To find out why, you need to know what the (-1)type is Num n => n, and you need to read how it is -interpreted with or without parsers in front of it.

The next function is the "correct" version of your function:

f x = map (subtract 1) x

You should be able to determine the type of this function if I say that:

subtract 1 :: Num n => n -> n
map :: (a -> b) -> [a] -> [b]
+2
source

I did it myself: P

(map) - (1 x)
(-)::Num a => a->a->->a
1::Num b=> b
x::e
map::(c->d)->[c]->[d]
map::a
a\(c->d)->[c]->[d]
(1 x)::a
1::e->a
f::(Num ((c->d)->[c]->[d]),Num (e->(c->d)->[c]->[d])) => e->(c->d)->[c]->[d]
0
source

All Articles