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

Martin Tomko martin.tomko at geo.uzh.ch
Tue Sep 28 10:07:33 EDT 2010


Dear all,
I want to have a function that acts only on lists of length 3 (I have a 
function that filters a list of lists and returns only those of that 
length). I guess I could change them into tuples (is there a way?), but 
anyway.
Is there a way to specify in the signature that the function should only 
match such lists, or do I have to do pattern mattching in order to 
exclude other possibilities?:

getTernaryRelationship :: [a] -> [a]
getTernaryRelationship ls = if (length ls /= 3) then error "not a 
ternary rel" else ...

thanks
Martin



More information about the Beginners mailing list