[Haskell-cafe] Help with how to concatenate with own datatypes
eldavido_ at hotmail.com
Fri Mar 11 02:41:14 CET 2011
I´m doing a project in haskell and I need to define an operator that
concatenate some own defined data types, just like the operator ++ does for
lists. I don´t see how to define the operator recursively since this adding
function (:) doesn´t work on my own data types.
This is my code:
data Allele = Aone | Atwo
type Lifespan = Int
data Population = Pop [(Allele,Allele,Lifespan)]
genepool :: Population
genepool = Pop 
--can only concatenate 2 elements
(+-) :: Population -> Population -> Population
Pop [(a,b,c)] +- Pop  = Pop [(a,b,c)]
Pop [(a,b,c)] +- Pop [(d,e,f)] = Pop [(a,b,c),(d,e,f)]
--and thats why this function goes non-exhaustive.
gpinsertaoneaone :: Int -> Int -> Population
gpinsertaoneaone 0 age = genepool
gpinsertaoneaone n age = Pop [(Aone,Aone,70-age)] +- gpinsertaoneaone (n-1)
Thx for help and advice!
View this message in context: http://haskell.1045720.n5.nabble.com/Help-with-how-to-concatenate-with-own-datatypes-tp3424433p3424433.html
Sent from the Haskell - Haskell-Cafe mailing list archive at Nabble.com.
More information about the Haskell-Cafe