Two module Up.hs and Down.hs
module Up (isSortedUp) where
isSortedUp x y z = if x>y && y>z then return(True) else return(False)
module Down (isSortedDown) where
isSortedDown x y z = if x<y && y<z then return(True) else return(False)
And the main program Main.hs
import System.Environment
import Up
import Down
main = do
args<-getArgs
let a = read(args !! 0)
let b = read(args !! 1)
let c = read(args !! 2)
if (isSortedUp a b c || isSortedDown a b c)
then putStrLn "True"
else putStrLn "False"
During compilation I get the following error:
Couldn't match expected type `Bool' with actual type `m0 Bool'
In the return type of a call of `isSortedUp'
In the first argument of `(||)', namely `isSortedUp a b c '
In the expression: (isSortedUp a b c || isSortedDown a b c)
You seem to be confused about
return. It is not a keyword for returning values like in other programming languages. In Haskell,returnis a function that promotes a pure value to a monadic one (e.g. anIntto anIO Int). You don’t use it for non-monadic code.Also, instead of writing
if foo then True else False, you can simply writefoo:Your
mainfunction can also be simplified a little using pattern matching and the fact thatprinton booleans prints"True"or"False".