Xavier Pinho is correct. The operators (<|)
and (|>)
are ordinary functions, but only data constructors may be used in patterns. (Yes, they're listed in the docs under the title Construction, because they're used to construct sequences out of components, but they're not technically data constructors.)
The library offers two functions viewl
and viewr
to create members of datatypes ViewL
and ViewR
. These have constructors :<
and :>
that can be matched on.
An example:
s :: Seq Int
s = fromList [1,2,3]
test1 :: (Int, Seq Int)
test1 = case viewl s of
x :< xs -> (x, xs)
test2 :: (Seq Int, Int)
test2 = case viewr s of
xs :> x -> (xs, x)
The views are also convenient to use with the ViewPatterns
language extension. If enabled, you can say
test3 :: Seq Int -> (Int, Seq Int)
test3 (viewl -> x :< xs) = (x, xs)
to match on an incoming sequence as if it was a list.