[Haskell-beginners] ignature for a list of a set length

edgar klerks edgar.klerks at gmail.com
Tue Sep 28 11:20:23 EDT 2010

I think it is simpler to use the Maybe type for this. If you only  search
for ternary relations, you can write a function, which only converts a list
to a 3-tuple if it is of length three and otherwise it returns nothing. Then
with catMaybes :: [Maybe a] -> [a], you can convert it back to a list with
only 3-tuples.

import Data.Maybe

getLengthThree = catMaybes . fmap toTup
    where toTup (x:y:z:[]) = Just (x,y,z)
          toTup _ = Nothing
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/beginners/attachments/20100928/1405128f/attachment.html

More information about the Beginners mailing list