Reputation: 340
I have been trying to create a function in Haskell that will take a non-negative value which corresponds to minutes and return it in the format (days,hours,minutes) e.g. 4000 minutes will give (2, 18, 39).
My code keeps returning the error "file:.\prac0.hs:27 - Syntax error in input (unexpected `|')
" on load.
Here is my code:
dayshoursmins :: Int->(Int,Int,Int)
dayshoursmins n = (x,y,z)
| n==0 = 0
| n`div`1440 =>1 = x && dayshoursmins(n`mod`1440)
| n`div`60 < 24 = y && dayshoursmins(n`mod`60)
| n < 60 = z
Upvotes: 0
Views: 60
Reputation: 476967
The pipe (|
) is used as a guard, what you need is a where
clause I think:
dayshoursmins :: Int->(Int,Int,Int)
dayshoursmins n = (d,h,m)
where d = div n 1440
dm = mod n 1440
h = div dm 60
m = mod dm 60
Running this with ghci
gives:
*Main> dayshoursmins 2016
(1,9,36)
I don't really understand your code: it does seem to mix all kinds of concepts. After the =
operator, you cannot put guards anymore.
Upvotes: 4