creatur-5.9.30: Framework for artificial life experiments.
Copyright(c) 2013-2021 Amy de Buitléir
LicenseBSD-style
Maintaineramy@nualeargais.ie
Stabilityexperimental
Portabilityportable
Safe HaskellSafe-Inferred
LanguageHaskell2010

ALife.Creatur.Genetics.Diploid

Description

TODO

Synopsis

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.

Minimal complete definition

Nothing

Methods

express :: g -> g -> g Source #

Given two possible forms of a gene, express takes into account any dominance relationship, and returns a gene representing the result.

default express :: (Generic g, GDiploid (Rep g)) => g -> g -> g Source #

Instances

Instances details
Diploid Bool Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: Bool -> Bool -> Bool Source #

Diploid Char Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: Char -> Char -> Char Source #

Diploid Double Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Diploid Int Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: Int -> Int -> Int Source #

Diploid Word Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: Word -> Word -> Word Source #

Diploid Word8 Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: Word8 -> Word8 -> Word8 Source #

Diploid Word16 Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Diploid Word32 Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Diploid Word64 Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Diploid a => Diploid [a] Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: [a] -> [a] -> [a] Source #

Diploid a => Diploid (Maybe a) Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: Maybe a -> Maybe a -> Maybe a Source #

(Diploid a, Diploid b) => Diploid (a, b) Source # 
Instance details

Defined in ALife.Creatur.Genetics.Diploid

Methods

express :: (a, b) -> (a, b) -> (a, b) Source #

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