1

So I am trying to implement a maximum function but for some reason I am getting a parse error on the last line "mymax x:y:ys = ..... " . What is the reason for that error? Thanks!

mymax :: Ord a=>[a]->Maybe a
mymax [] = Nothing
mymax [x] = Just x
mymax x:y:xs = if (x < y) 
            then mymax(y:xs) 
            else mymax(x:xs)
Georgi Angelov
  • 4,338
  • 12
  • 67
  • 96
  • Possible duplicate of [Haskell: Parse error in pattern](https://stackoverflow.com/questions/8561762/haskell-parse-error-in-pattern) – Chris Martin Sep 06 '17 at 07:53

2 Answers2

3

You're missing the parentheses:

mymax (x:y:xs) = if (x < y) 
                 ...
fjarri
  • 9,546
  • 39
  • 49
2

Put parenthesis around x:y:xs

mymax (x:y:xs) = ...
bheklilr
  • 53,530
  • 6
  • 107
  • 163