Function with a & # 8594; a & # 8594; is possible in Haskell?

I look at the Haskell programming book and in the exercise on page 140, the author states the following:

A hypothetical function a->a->a has two possible implementations. Write both possible versions.

I assume that it a -> a -> awill mean a function that takes two arguments (a and a)- (which does not make sense to me, and if I declare a function with two arguments as a, ghci rightly complains too) and returnsa

I think I have something missing, what is it?

+4
source share
2 answers

Perhaps to think about this problem is to imagine how much we do not know about your arguments a and a.

For example, one cannot say the following:

someFunc :: a -> a -> a
someFunc x y = x == y

typecheck, , a Eq. , a , , ( , ).

:

ident :: a -> a
ident x = ...

x. , :

ident x = x

, .

, , , . , , . , , , :

someFunc1 :: a -> a -> a
someFunc1 x y = x

someFunc2 :: a -> a -> a
someFunc2 x y = y

.

+10

let f :: a -> a -> a, a, 2 1-/2- , ..

f x _ = x

f _ x = x
+6

Source: https://habr.com/ru/post/1689178/


All Articles