🎉 Exercism Research is now launched. Help Exercism, help science and have some fun at research.exercism.io 🎉
Avatar of hyphenrf

hyphenrf's solution

to RNA Transcription in the OCaml Track

Published at Apr 29 2020 · 1 comment
Test suite

Given a DNA strand, return its RNA complement (per RNA transcription).

Both DNA and RNA strands are a sequence of nucleotides.

The four nucleotides found in DNA are adenine (A), cytosine (C), guanine (G) and thymine (T).

The four nucleotides found in RNA are adenine (A), cytosine (C), guanine (G) and uracil (U).

Given a DNA strand, its transcribed RNA strand is formed by replacing each nucleotide with its complement:

  • G -> C
  • C -> G
  • T -> A
  • A -> U

Getting Started

  1. Install the Exercism CLI.

  2. Install OCaml.

  3. For library documentation, follow Useful OCaml resources.

Running Tests

A Makefile is provided with a default target to compile your solution and run the tests. At the command line, type:


Submitting Incomplete Solutions

It's possible to submit an incomplete solution so you can see how others have completed the exercise.

Feedback, Issues, Pull Requests

The exercism/ocaml repository on GitHub is the home for all of the Ocaml exercises.

If you have feedback about an exercise, or want to help implementing a new one, head over there and create an issue or submit a PR. We welcome new contributors!


Hyperphysics http://hyperphysics.phy-astr.gsu.edu/hbase/Organic/transcription.html


open Base
open OUnit2

let char_of_variant = function
  | `A -> 'A' | `C -> 'C' | `G -> 'G' | `T -> 'T' | `U -> 'U'
let printer l = List.map ~f:char_of_variant l |> String.of_char_list
let ae exp got _test_ctxt = assert_equal ~printer exp got

let tests =
  ["transcribes empty list">::
   ae [] (Rna_transcription.to_rna []);
   "transcribes cytidine">::
   ae [`G] (Rna_transcription.to_rna [`C]);
   "transcribes guanosine">::
   ae [`C] (Rna_transcription.to_rna [`G]);
   "transcribes adenosie">::
   ae [`U] (Rna_transcription.to_rna [`A]);
   "transcribes thymidine">::
   ae [`A] (Rna_transcription.to_rna [`T]);
   "transcribes multiple">::
   ae [`U; `G; `C; `A; `C; `C; `A; `G; `A; `A; `U; `U]
     (Rna_transcription.to_rna [`A; `C; `G; `T; `G; `G; `T; `C; `T; `T; `A; `A])

let () =
  run_test_tt_main ("rna-transcription tests" >::: tests)
type dna = [ `A | `C | `G | `T ]
type rna = [ `A | `C | `G | `U ]

let to_rna = List.map ( function `G -> `C
                               | `C -> `G
                               | `T -> `A
                               | `A -> `U )

Community comments

Find this solution interesting? Ask the author a question to learn more.
Avatar of hyphenrf

So what's the difference between

type dna = [ `A | `C | `G | `T ]


type dna = A | C | G | T


What can you learn from this solution?

A huge amount can be learned from reading other people’s code. This is why we wanted to give exercism users the option of making their solutions public.

Here are some questions to help you reflect on this solution and learn the most from it.

  • What compromises have been made?
  • Are there new concepts here that you could read more about to improve your understanding?