I am trying to learn to work with algebraic data type, but i have some trouble.
So I want to create a Chain that has Gold, Silver or Platinum Links.
Currently i have the following dataTypes:
data Link = G | S | P deriving (Eq, Show)
data Chain = Empty | Join Chain Link Chain
But now I am unsure how to construct the chain
I tried to construnct a chain that has the following Links in this order: Platinum, Gold, Gold
This is how i constructed it:
chain1 = (Join Empty G (Join Empty G (Join Empty P (Empty))))
But i am unsure if it is correct.
Thanks in advance!
Your
Chaintype allows for an arbitrary tree structure (indeed, it's isomorphic to the common definition of a binary tree,Instead, I would represent a chain as being implicitly joined using the adjacent ends of two smaller chains (and for simplicity, disallowing empty chains).
If you want to join two chains with a given link, use a regular function.