When working through “Haskell Programming from First Principles,” I am puzzled by the answer to the following question:
If the type kesselis equal (Ord a, Num b) => a -> b -> a, then the type kessel 1 2isa) Integerb) Intc) ad) (Num a, Ord a) => ae) Ord a => af)Num a => a
If the type kesselis equal (Ord a, Num b) => a -> b -> a, then the type kessel 1 2is
kessel
(Ord a, Num b) => a -> b -> a
kessel 1 2
a) Integerb) Intc) ad) (Num a, Ord a) => ae) Ord a => af)Num a => a
Integer
Int
a
(Num a, Ord a) => a
Ord a => a
Num a => a
Answer: d), but I think the answer should be e), since the only requirement in the type signature for the first argument (a) is that it is Ord. So why not come back?
Ord
kessel 'd' 2
valid and has type Char- nothing about Num!
Char
Num
What? I do not understand?
Thank you for your help.
1 - Num a => a. kessel, (Num a, Ord a) => a, kessel Ord . , (Num a, Ord a) => a .
1
, . , . :
kessel :: Ord a => a -> a
kessel 1 (Num a, Ord a) => a. Num , 1 - kessel.
kessel 1
kessel 'd' 2 Char, Ord Char => Char, Char , Ord, .
Ord Char => Char
kessel 'd' 2Char - Num!
Char - Num!
! kessel 1 2 kessel 'd' 2 ,
λ> kessel = undefined :: (Ord a, Num b) => a -> b -> a kessel :: (Num b, Ord a) => a -> b -> a λ> :t kessel 1 2 kessel 1 2 :: (Num a, Ord a) => a λ> :t kessel 'd' 2 kessel 'd' 2 :: Char
, kessel .
Source: https://habr.com/ru/post/1671407/More articles:How to change the color of a button, glyphicon and text when clicking on it? - javascriptПри изменении триггера триггера один раз до состояния "Истина" или "Неверно" - javascriptОшибка при создании проекта: ошибка при создании игрока, поскольку скрипты компилируют ошибки в редакторе - c#How does the bluetooth a2dp profile work? - androidИзмените цвет графика в зависимости от плотности (хранящейся в массиве) в линейном графике в matplotlib - pythonMarkLogic: Failed to update host name - waiting for retry - amazon-cloudformationdjango nginx: [emerg] open () "/ etc / nginx / proxy_params" failed (2: There is no such file or directory) in / etc / nginx / sites -enabled / myproject: 11 - djangoAngular 2 - form data - javascriptapp: processDebugResources - IllegalArgumentException (no error message) - androidLint failed while using gradle build android - android applicationAll Articles