Translating that into Haskell, I get:
check_each :: Int -> [Int] -> Bool -> Int -> (Bool,Bool,Int)
check_each x (y:_) _ last | y==x && x==last = (True,False,x)
check_each x (y:_) _ last | y>x && x==last = (True,True,x)
check_each x (y:_) found _ | y>x = (True,found,x)
check_each x _ found _ = (False,found,x)
is_valid :: (Bool,Bool,Int) -> [Int] -> Bool
is_valid (False,_,_) _ = False
is_valid (True,True,-1) [_] = False
is_valid (True,True,_) [_] = True
is_valid (True,found,shortDup) (h:t) = is_valid (check_each h t found shortDup) t
which is
ugly, certainly, but compiles fine (ghc). The uglyness mainly comes from the data structures, and I don't know enough about the domain to suggest better ones (there might not
be better ones).