Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GHCi, version 7.0.4: http://www.haskell.org/ghc/ :? for help
- Loading package ghc-prim ... linking ... done.
- Loading package integer-gmp ... linking ... done.
- Loading package base ... linking ... done.
- Loading package ffi-1.0 ... linking ... done.
- ghci> --Distribution of genotypes in the second generation
- ghci> let split _ [] = []; split n xs = (take n xs):split (drop n xs)
- <interactive>:1:47:
- Couldn't match expected type `[[a0]]'
- with actual type `[a0] -> [[a0]]'
- In the return type of a call of `split'
- In the second argument of `(:)', namely `split (drop n xs)'
- In the expression: (take n xs) : split (drop n xs)
- ghci> let split _ [] = []; split n xs = (take n xs):split n (drop n xs)
- ghci> split 2 "aabbb"
- ["aa","bb","b"]
- ghci> :{
- Prelude| let variants f m = variants' (split 2 f) (split 2 m) where
- Prelude| variants' [] [] = []
- Prelude| variants' (f:fs) (m:ms) = [[fa, ma]:rest | fa <- f, ma <- m, rest <- variants' fs ms]
- Prelude| variants' _ _ = error "Parents have different genomes size"
- Prelude| :}
- ghci> variants "Aa" "Aa"
- []
- ghci> split 2 "Aa"
- ["Aa"]
- ghci> :t variants
- variants :: [t] -> [t] -> [[[t]]]
- ghci> :{
- Prelude| let variants f m = variants' (split 2 f) (split 2 m) where
- Prelude| variants' [] [] = []
- Prelude| variants' (f:fs) (m:ms) = [[fa, ma] ++ rest | fa <- f, ma <- m, rest <- variants' fs ms]
- Prelude| :}
- ghci> :t variants
- variants :: [a] -> [a] -> [[a]]
- ghci> variants "Aa" "Aa"
- []
- ghci> :{
- Prelude| let variants f m = variants' (split 2 f) (split 2 m) where
- Prelude| variants' [] [] = [[]]
- Prelude| variants' (f:fs) (m:ms) = [[fa, ma] ++ rest | fa <- f, ma <- m, rest <- variants' fs ms]
- Prelude| :}
- ghci> variants "Aa" "Aa"
- ["AA","Aa","aA","aa"]
- ghci> variants "AaBb" "AaBb"
- ["AABB","AABb","AAbB","AAbb","AaBB","AaBb","AabB","Aabb","aABB","aABb","aAbB","aAbb","aaBB","aaBb","aabB","aabb"]
- ghci> import Data.List
- ghci> import Data.Sort
- <no location info>:
- Could not find module `Data.Sort':
- Use -v to see a list of the files searched for.
- ghci> import Data.Ratio
- ghci> let distribution(\group -> (head group, length group % length f)) . group . sort . map sort . variants
- <interactive>:1:103: parse error (possibly incorrect indentation)
- ghci> let distribution = map (\group -> (head group, length group % length f)) . group . sort . map sort . variants
- <interactive>:1:70: Not in scope: `f'
- ghci> let distribution f m = map (\group -> (head group, length group % length f)) . group . sort . map sort $ variants f m
- ghci> let distribution f m = map (\group -> (head group, length group % length f ^ 2)) . group . sort . map sort $ variants f m
- ghci> distribution "Aa" "Aa"
- [("AA",1 % 4),("Aa",1 % 2),("aa",1 % 4)]
- ghci> distribution "AaBb" "AaBb"
- [("AABB",1 % 16),("AABb",1 % 8),("AAbb",1 % 16),("ABBa",1 % 8),("ABab",1 % 4),("Aabb",1 % 8),("BBaa",1 % 16),("Baab",1 % 8),("aabb",1 % 16)]
- ghci> import Data.Monoid
- ghci> import Data.Char
- ghci> let compAllel = comparing toLower <+> compare
- <interactive>:1:17: Not in scope: `comparing'
- <interactive>:1:35: Not in scope: `<+>'
- ghci> import Data.Ord
- ghci> let compAllel = comparing toLower `mappend` compare
- ghci> zipWith2 compAllel "AABBaabb" "ababABAB"
- <interactive>:1:1: Not in scope: `zipWith2'
- ghci> zipWith compAllel "AABBaabb" "ababABAB"
- [LT,LT,GT,LT,GT,LT,GT,GT]
- ghci> sortBy compAllel "BaBAaABaABa"
- "AAAaaaaBBBB"
- ghci> let distribution f m = map (\group -> (head group, length group % 2 ^ length f)) . group . sort . map (sortBy compAllel) $ variants f m
- ghci> distribution "AaBb" "AaBb"
- [("AABB",1 % 16),("AABb",1 % 8),("AAbb",1 % 16),("AaBB",1 % 8),("AaBb",1 % 4),("Aabb",1 % 8),("aaBB",1 % 16),("aaBb",1 % 8),("aabb",1 % 16)]
- ghci>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement