You have a fundamental representation problem:
you should not use a Char to describe a nucleotide base. Allowed values are only A, C, T and G. With this representation it could also be Z or ;...
Instead, create a new type:
type DNANucleotideBase
= Adenine
| Thymine
| Guanine
| Cytosine
or you can also use A | T | G | C for brevity if that does not conflict with anything.
That way you will not have to consider incorrect values because they cannot exist.
Also consider using a case x of rather than multiple ifs.
You won't need Result in this case if you make impossible state impossible :-)
BTW, have you tried the official Elm documentation? I'm not sure how they hold up for people new to functional programming but I myself found them sufficient (for the fundamentals anyway).
I would argue this isn't a good exercise then. There are better way to explain result, that do not promote improper state representation (such as making a safe division function).
I apologize for being harsh. I understand writing this stuff is time-consuming and sometimes hard, but I do believe this (making impossible state impossible) is an important concept, central to Elm and FP in general.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
You have a fundamental representation problem:
you should not use a
Char
to describe a nucleotide base. Allowed values are onlyA
,C
,T
andG
. With this representation it could also beZ
or;
...Instead, create a new type:
or you can also use
A | T | G | C
for brevity if that does not conflict with anything.That way you will not have to consider incorrect values because they cannot exist.
Also consider using a
case x of
rather than multipleif
s.First, I'm gonna try deal wit the case and then with the Result type and then I will add types.
P.S. I just got my hand on frondendmasters elm courses. I will postpone solving the problem. Want to watch the videos first.
You won't need
Result
in this case if you make impossible state impossible :-)BTW, have you tried the official Elm documentation? I'm not sure how they hold up for people new to functional programming but I myself found them sufficient (for the fundamentals anyway).
The exercise is written such that it expects to get a
Result
.github.com/exercism/elm/blob/maste...
I would argue this isn't a good exercise then. There are better way to explain result, that do not promote improper state representation (such as making a safe division function).
I apologize for being harsh. I understand writing this stuff is time-consuming and sometimes hard, but I do believe this (making impossible state impossible) is an important concept, central to Elm and FP in general.