orderedq f [] = True
orderedq f (x:[]) = True
orderedq f (x:y:zs) = and [(f x y), (orderedq f zs)]
num_orderedq xs = orderedq <= xs
ghci
says, when trying to load using :l [file name]
says:
[1 of 1] Compiling Main ( route-combinations.hs, interpreted )
route-combinations.hs:9:1: error:
* Non type-variable argument
in the constraint: Ord ((t -> t -> Bool) -> [t] -> Bool)
(Use FlexibleContexts to permit this)
* When checking the inferred type
num_orderedq :: forall t.
Ord ((t -> t -> Bool) -> [t] -> Bool) =>
((t -> t -> Bool) -> [t] -> Bool) -> Bool
|
9 | num_orderedq xs = orderedq <= xs
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Failed, no modules loaded.
Is my typing wrong?
What is the correct type signature for the code? It doesn't accept this:
orderedq :: (a -> a -> Bool) -> [a] -> Bool
orderedq f [] = True
orderedq f (x:[]) = True
orderedq f (x:y:zs) = and [(f x y), (orderedq f zs)]
num_orderedq :: [a] -> Bool
num_orderedq xs = orderedq <= xs
orderedq
is a function, so this can not be "smaller" thanxs
. – Willem Van Onsemnum_orderedq xs = orderedq <= xs
? I am trying to pass<=
andxs
as arguments. If the problem is that<=
is being assumed to be an infix function, how can I know that this is the case with functions in the future, and pass that function to another function? – SultanLegend