我是哈斯凯尔的新人。我尝试编译一些例子,但我不知道编译器试图告诉我什么。 这是我的代码:
import Data.List
import System.IO
max' :: int->int->int
max' n m
| (n <= m) = m
| otherwise = n
maximum' :: [int]->int
maximum' [a]=a
maximum' (x:xs) = max' x (maximum' xs)
sort' :: [int]->[int]
sort' [] =[]
sort' (x:xs) = sort'[y|y<-(x:xs),y < maximum'(x:xs)]++[y'|y'<-(x:xs),y' == maximum'(x:xs)]
,这是编译器的输出:
Prelude> :r
[1 of 1] Compiling Main ( test.hs, interpreted )
Failed, modules loaded: none.
test.hs:6:22:
No instance for (Ord int) arising from a use of ‘<=’
Possible fix:
add (Ord int) to the context of
the type signature for max' :: int -> int -> int
In the expression: (n <= m)
In a stmt of a pattern guard for
an equation for ‘max'’:
(n <= m)
In an equation for ‘max'’:
max' n m
| (n <= m) = m
| otherwise = n
test.hs:15:36:
No instance for (Ord int) arising from a use of ‘<’
Possible fix:
add (Ord int) to the context of
the type signature for sort' :: [int] -> [int]
In the expression: y < maximum' (x : xs)
In a stmt of a list comprehension: y < maximum' (x : xs)
In the first argument of ‘sort'’, namely
‘[y | y <- (x : xs), y < maximum' (x : xs)]’
test.hs:15:73:
No instance for (Eq int) arising from a use of ‘==’
Possible fix:
add (Eq int) to the context of
the type signature for sort' :: [int] -> [int]
In the expression: y' == maximum' (x : xs)
In a stmt of a list comprehension: y' == maximum' (x : xs)
In the second argument of ‘(++)’, namely
‘[y' | y' <- (x : xs), y' == maximum' (x : xs)]’
编译器指向我代码中的所有逻辑运算符