Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Haskell type dessignation

I have to dessignate types of 2 functions(without using compiler :t) i just dont know how soudl i read these functions to make correct steps.

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

Well i'm a bit confuse how it will be parsed

like image 305
whd Avatar asked Jul 15 '26 21:07

whd


1 Answers

Function application, or "the empty space operator" has higher precedence than any operator symbol, so the first line parses as f x = map - (1 x), which will most likely1 be a type error.

The other example is parenthesized the way it looks, but note that (-1) desugars as negate 1. This is an exception from the normal rule, where operator sections like (+1) desugar as (\x -> x + 1), so this will also likely1 be a type error since map expects a function, not a number, as its first argument.

1 I say likely because it is technically possible to provide Num instances for functions which may allow this to type check.

like image 113
hammar Avatar answered Jul 17 '26 21:07

hammar