I am new with elm. Elm version is 0.19. I am trying to use Ranndom.int to select ship type, but don't know how to do it. What should I do with the function numToShip? Change the type?
Here is my code ...
type ShipType
= Battleship
| Cruiser
| Destroyer
| Submarine
numToShip : Int -> ShipType
numToShip num =
case num of
0 -> Destroyer
1 -> Battleship
2 -> Cruiser
_ -> Submarine
shipName : ShipType -> String
shipName shipType =
case shipType of
Destroyer ->
"Destroyer"
Battleship ->
"Battleship"
Cruiser ->
"Cruiser"
Submarine ->
"Submarine"
randomShip : String
randomShip =
shipName (numToShip (Random.int 0 3) )
error message is:
The 1st pattern in this `case` causing a mismatch:
146| case num of
147|> 0 -> Destroyer
148| 1 -> Battleship
149| 2 -> Cruiser
150| _ -> Submarine
The first pattern is trying to match integers:
Int
But the expression between `case` and `of` is:
Random.Generator Int
These can never match! Is the pattern the problem? Or is it the expression?