Question
Please help me with these exericises in Haskell. 1. The function church takes an integer n as its argument and returns a function which composes
Please help me with these exericises in Haskell.
1. The function church takes an integer n as its argument and returns a function which composes any unary function n times.
For example:
*Main> :t church
church :: Int -> (c -> c) -> c -> c
*Main> (church 4) tail "ABCDEFGH"
"EFGH"
Write church using foldr.
2. Write a function trees which takes a list of leaf values as its argument and returns a list of all binary trees with the given leaves.
For example, *Main> :t trees
trees :: (Ord t) => [t] -> [Btree t]
*Main> (trees "ABCDE") !! 114
Fork (Leaf E) (Fork (Fork (Leaf A) (Fork (Leaf C) (Leaf B))) (Leaf D))
*Main> length (trees [0..4])
1680
3. A DNA molecule is a sequence of four bases which are conventionally represented using the characters A, G, C, and T. Genomes represented by DNA molecules are subject to four different types of point mutations:
insertions - A base is inserted between two adjacent points in a genome.
deletions - A point is deleted from a genome.
substitutions - A base at a point is replaced with another base.
transpositions - The bases at two adjacent points are exchanged.
Give definitions for Haskell functions insertions, deletions, substitutions and transpositions which take a genome represented as a string and return a list of all genomes produced by single point point mutations of the specifed kind.
For example:
*Main> insertions "GC"
["AGC","GAC","GCA","GGC","GGC","GCG","CGC","GCC","GCC", "TGC","GTC","GCT"]
*Main> deletions "AGCT"
["GCT","ACT","AGT","AGC"]
*Main> substitutions "ACT"
["ACT","AAT","ACA","GCT","AGT","ACG","CCT","ACT","ACC", "TCT","ATT","ACT"]
*Main> transpositions "GATC"
["AGTC","GTAC","GACT"]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started