Copyright | (c) 2013-2021 Amy de Buitléir |
---|---|
License | BSD-style |
Maintainer | amy@nualeargais.ie |
Stability | experimental |
Portability | portable |
Safe Haskell | Safe-Inferred |
Language | Haskell2010 |
TODO
Documentation
class Diploid g where Source #
A diploid agent has two complete sets of genetic instructions.
Instances of this class can be thought of as paired genes or
paired instructions for building an agent.
When two instructions in a pair differ, dominance relationships
determine how the genes will be expressed in the agent.
Minimal complete definition:
.express
Nothing
express :: g -> g -> g Source #
Given two possible forms of a gene,
takes into
account any dominance relationship, and returns a gene
representing the result.express
Instances
Diploid Bool Source # | |
Diploid Char Source # | |
Diploid Double Source # | |
Diploid Int Source # | |
Diploid Word Source # | |
Diploid Word8 Source # | |
Diploid Word16 Source # | |
Diploid Word32 Source # | |
Diploid Word64 Source # | |
Diploid a => Diploid [a] Source # | |
Defined in ALife.Creatur.Genetics.Diploid | |
Diploid a => Diploid (Maybe a) Source # | |
(Diploid a, Diploid b) => Diploid (a, b) Source # | |
Defined in ALife.Creatur.Genetics.Diploid |
Deriving generic instances of Diploid
You can easily use the generic mechanism provided to automatically
create implementations of Diploid
for arbitrarily complex types.
First, you need to import:
import GHC.Generics
Instances of Diploid
have been defined for some base types.
You will need to create instances for any additional base types
that you use.
If the arrays are of different lengths, the result will be as long as the shorter array.
λ> express [1,2,3,4] [5,6,7,8,9] :: [Int] [1,2,3,4]
You can automatically derive instances for more complex types:
data MyType = MyTypeA Bool | MyTypeB Int | MyTypeC Bool Int [MyType] deriving (Show, Generic)
instance Diploid MyType instance Diploid [MyType]
λ> express (MyTypeA True) (MyTypeA False) MyTypeA True
λ> express (MyTypeB 2048) (MyTypeB 36) MyTypeB 36
Even with complex values, the implementation should just "do the right thing".
λ> express (MyTypeC False 789 [MyTypeA True, MyTypeB 33, MyTypeC True 12 []]) (MyTypeC True 987 [MyTypeA False, MyTypeB 11, MyTypeC True 3 []]) MyTypeC True 789 [MyTypeA True,MyTypeB 11,MyTypeC True 3 []]
When a type has multiple constructors, the constructors that appear earlier in the definition are dominant over those that appear later. For example:
λ> express (MyTypeA True) (MyTypeB 7) MyTypeA True
λ> express (MyTypeB 4) (MyTypeC True 66 []) MyTypeB 4