Avatar of paulfioravanti

paulfioravanti's solution

to RNA Transcription in the Elm Track

Published at Jun 14 2019 · 0 comments
Test suite


This exercise has changed since this solution was written.

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

Elm Installation

Refer to the Installing Elm page for information about installing elm.

Writing the Code

The first time you start an exercise, you'll need to ensure you have the appropriate dependencies installed. Thankfully, Elm makes that easy for you and will install dependencies when you try to run tests or build the code.

Execute the tests with:

$ elm-test

Automatically run tests again when you save changes:

$ elm-test --watch

As you work your way through the test suite, be sure to remove the skip <| calls from each test until you get them all passing!


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

Submitting Incomplete Solutions

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


module Tests exposing (tests)

import Expect
import RNATranscription exposing (toRNA)
import Test exposing (..)

tests : Test
tests =
    describe "RNATranscription"
        [ test "complement of cytosine is guanine" <|
            \() -> Expect.equal (Ok "G") (toRNA "C")
        , skip <|
            test "complement of guanine is cytosine" <|
                \() -> Expect.equal (Ok "C") (toRNA "G")
        , skip <|
            test "complement of thymine is adenine" <|
                \() -> Expect.equal (Ok "A") (toRNA "T")
        , skip <|
            test "complement of adenine is uracil" <|
                \() -> Expect.equal (Ok "U") (toRNA "A")
        , skip <|
            test "complement" <|
                \() -> Expect.equal (Ok "UGCACCAGAAUU") (toRNA "ACGTGGTCTTAA")
module RNATranscription exposing (toRNA)

import Dict exposing (Dict)

toRNA : String -> Result Char String
toRNA dna =
        |> String.foldr rnaTranscription (Ok "")


rnaTranscription : Char -> Result Char String -> Result Char String
rnaTranscription dna acc =
        transcription =
                |> Dict.get dna
    case transcription of
        Just rna ->
                |> Result.map (String.cons rna)

        Nothing ->
            Err dna

rnaTranscriptions : Dict Char Char
rnaTranscriptions =
        [ ( 'A', 'U' )
        , ( 'C', 'G' )
        , ( 'G', 'C' )
        , ( 'T', 'A' )

Community comments

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

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?