battleship

Safe HaskellSafe

Ship

Description

This trusted module defines the datatype of ships, along with associated functions.

Synopsis

Documentation

data Ship

The ships.

Constructors

Carrier

The carrier.

Battleship

The battleship.

Submarine

The submarine.

Destroyer

The destroyer.

PatrolBoat

The patrol boat.

size :: Ship -> Int

Number of cells in a ship:

   size Carrier    = 5
   size Battleship = 4
   size Submarine  = 3
   size Destroyer  = 3
   size PatrolBoat = 2

shipToStr :: Ship -> String

Description of a ship (first letters must be distinct and in lowercase):

   shipToStr Carrier    = "carrier"
   shipToStr Battleship = "battleship"
   shipToStr Submarine  = "submarine"
   shipToStr Destroyer  = "destroyer"
   shipToStr PatrolBoat = "patrol boat"

shipToLetter :: Ship -> Char

First letter of ship's description.

ships :: [Ship]

List of ships, in order given by datatype.

ord :: Ship -> Int

Index (starting from 0) of ship in list of ships.