I got 2 types
type Rotor = String
type Reflector =[(Char, Char)]
and I know type SimpleEnigma
has exactly 3 Rotor
and 1 Reflector
. How can I define SimpleEnigma
?
Thanks in advance!!
data SimpleEnigma = SimpleEnigma Rotor Rotor Rotor Reflector
We use the data
keyword to define a new algebraic data type that holds three values of type Rotor
and one value of type Reflector
.
Note that you change the name of the value constructor (SimpleEnigma
to the right of the equal) to something other than SimpleEnigma
and change the order of types Rotor
and Reflector
.
SimpleEnigma
to the right of the equal and if I use this type, what does it return?
SimpleEnigma
to the left is a type. SimpleEnigma
to the right is a value constructor: learnyouahaskell.com/…
Commented
Nov 7, 2016 at 0:58
type
keyword introduces a type alias, whereas the data
constructor introduces new ADTs.
Maybe
type? It's defined as data Maybe t = Just t | Nothing
i.e. Maybe t
is the type itself (on the left) and Just t
and Nothing
define the possible values of that type.
Commented
Nov 7, 2016 at 2:08