[Haskell-beginners] ignature for a list of a set length
Martin Tomko
martin.tomko at geo.uzh.ch
Tue Sep 28 11:39:50 EDT 2010
I like this suggestion, I will give it a go!
thanks, and also for the catMaybes function, I needed something like
that some days ago.
martin
On 9/28/2010 5:20 PM, edgar klerks wrote:
> 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
>
--
Martin Tomko
Postdoctoral Research Assistant
Geographic Information Systems Division
Department of Geography
University of Zurich - Irchel
Winterthurerstr. 190
CH-8057 Zurich, Switzerland
email: martin.tomko at geo.uzh.ch
site: http://www.geo.uzh.ch/~mtomko
mob: +41-788 629 558
tel: +41-44-6355256
fax: +41-44-6356848
More information about the Beginners
mailing list