I’ve got the function:
isSortedUp x y z = if x>y && y>z then True else False
and I want to put it into module UP.
This function I want to put into module down:
isSortedDown x y z = if x<y && y<z then True else False
And then call them in the main program:
import System.Environment
import Up
import Down
main = do
args<-getArgs
let a = args !! 0
let b = args !! 1
let c = args !! 2
if (isSortedUp a b c) || (isSortedDown a b c) then return (True) else return(False)
How to put and call this functions?
New code
Main.hs
import System.Environment
import Up
import Down
main = do
args<-getArgs
let a = args !! 0
let b = args !! 1
let c = args !! 2
if (isSortedUp a b c) || (isSortedDown a b c) then return(True) else return(False)
Up.hs
module Up (isSortedUp) where
isSortedUp x y z = if x>y && y>z then return(True) else return(False)
Down.hs
module Down (isSortedDown) where
isSortedDown x y z = if x<y && y<z then return(True) else return(False)
Modules in Haskell are broken up by file. So to put
isSortedDownin it’s own moduleDown, you’d create a new fileDown.hsand drop it’s contents inside with themoduledeclaration:Then, providing your
Mainmodule has access to this module (in the same directory, for instance), it should import and be accessible.For more information on modules in Haskell, read:
own modules” section — near the bottom)