Exercises part 2
Sharpen your skills in using dependent pairs and dependent records! In exercises 2 to 7 you have to decide yourself, when a function should return a dependent pair or record, when a function requires additional arguments, on which you can pattern match, and what other utility functions might be necessary.
-
Proof that the three encodings for nucleobases are isomorphic (meaning: of the same structure) by writing lossless conversion functions from
Acid1
toAcid2
and back. Likewise forAcid1
andAcid3
. -
Sequences of nucleobases can be encoded in one of two directions: Sense and antisense. Declare a new data type to describe the sense of a sequence of nucleobases, and add this as an additional parameter to type
Nucleobase
and typesDNA
andRNA
. -
Refine the types of
complement
andtranscribe
, so that they reflect the changing of sense. In case oftranscribe
, a strand of antisense DNA is converted to a strand of sense RNA. -
Define a dependent record storing the base type and sense together with a sequence of nucleobases.
-
Adjust
readRNA
andreadDNA
in such a way that the sense of a sequence is read from the input string. Sense strands are encoded like so: "5´-CGGTAG-3´". Antisense strands are encoded like so: "3´-CGGTAG-5´". -
Adjust
encode
in such a way that it includes the sense in its output. -
Enhance
getNucleicAcid
andtranscribeProg
in such a way that the sense and base type are stored together with the sequence, and thattranscribeProg
always prints the sense RNA strand (after transcription, if necessary). -
Enjoy the fruits of your labour and test your program at the REPL.
Note: Instead of using a dependent record, we could again have used a sum type of four constructors to encode the different types of sequences. However, the number of constructors required corresponds to the product of the number of values of each type level index. Therefore, this number can grow quickly and sum type encodings can lead to lengthy blocks of pattern matches in these cases.