haskell - Checking to see if a list is ordered consecutively -
Is there a Library function in Haskell that allows me to check whether the list is constantly sorted or not? like. [1,2,3,4] is valid, [1,2,3,10] is invalid.
Actually I can have a list that is between 3 to 5 elements and I am trying to check that the list has been ordered respectively.
My attempt (I'm not sure that this is a way to properly contact, it is being repetitive too)
isSucc :: [integer] - & Gt; Bool isSucc [] = True Haze (X: Y: zs) = if (x + 1) == y then true & amp; After working on this function, I'm planning to use it to filter the list lists (by putting the list in) (SEC: (y: zs) only and can be recorded only when
There is no standard work for this.
Here is a definite version of your function, by generalizing it, removing unnecessary conditions and adding missing ones: isSucc :: (Enum a, Eq a) = & Gt; [A] - & gt; Bool isSucc is [] = True Succ (X: []) = True is the SUCC (X: Y: ZS) | Y == succ x = isSucc $ y: zs is SUCC _ = wrong
Comments
Post a Comment