Site Map - skip to main content

Hacker Public Radio

Your ideas, projects, opinions - podcasted.

New episodes every weekday Monday through Friday.
This page was generated by The HPR Robot at

hpr2969 :: Crewing a spaceship in Haskell

How to calculate amount of crew needed for a spaceship

<< First, < Previous, , Latest >>

Thumbnail of Tuula
Hosted by Tuula on 2019-12-19 is flagged as Clean and is released under a CC-BY-SA license.
haskell, problem solving. (Be the first).
The show is available on the Internet Archive at:

Listen in ogg, spx, or mp3 format. Play now:

Duration: 00:22:38


A series looking into the Haskell (programming language)


Every spaceship in game needs a crew to operate it. Smaller ships with fewer components require less crew than huge ones with lots of components.


Unit stats lists amount of crew required to operate a spaceship and if they need sleeping quarters.

data UnitStats = UnitStats
    { unitStatsMinimumCrew :: ![CrewRequirement]
    , unitStatsNominalCrew :: ![CrewRequirement]
    , unitStatsCrewSpace :: !TotalCrewSpace
    , unitStatsCrewSpaceRequired :: !CrewSpaceReq
    } deriving (Show, Read, Eq)

Different positions a crew can have is an enumeration:

data CrewPosition =
    | Navigator
    | Signaler
    | SensorOperator
    | Gunner
    | Doctor
    | Nurse
    | Driver
    | Helmsman
    | Artificer
    | Crew
    | Passenger
    deriving (Show, Read, Eq, Enum, Bounded)
derivePersistField "CrewPosition"

Rank of a crew member isn’t a military rank, but rather their position in ship’s internal hierarchy:

data CrewRank =
    | FirstClass
    | Senior
    | Chief
    deriving (Show, Read, Eq, Enum, Bounded)
derivePersistField "CrewRank"

Amount of crew is newtype that helps me not to mix different types of numbers with each other.

newtype CrewAmount = CrewAmount { unCrewAmount :: Int }
    deriving (Show, Read, Eq, Ord, Num)

Total crew space of a ship is divided to three different types: steerage, standard and luxury.

data TotalCrewSpace = TotalCrewSpace
    { totalCrewSpaceSteerage :: !(CrewSpace SteerageQuarters)
    , totalCrewSpaceStandard :: !(CrewSpace StandardQuarters)
    , totalCrewSpaceLuxury :: !(CrewSpace LuxuryQuarters)
    } deriving (Show, Read, Eq)

Again, crew space is newtype so I don’t mix different types of numbers with each other.

data CrewSpace a =
    CrewSpace { unCrewSpace :: CrewAmount }
    deriving (Show, Read, Eq)

I could have modeled fact that vehicle might need crew space with Bool, but having a descriptive name and type is more to my liking.

data CrewSpaceReq =
    | CrewSpaceOptional
    deriving (Show, Read, Eq)
derivePersistField "CrewSpaceReq"

The fact that single person could manage multiple components is reflected by ComponentCrewReq having Double instead of Integer

-- | Crew requirements for a component
data ComponentCrewReq =
    ComponentCrewReq CrewPosition Double
    deriving (Show, Read, Eq)

In closing

If you have questions, comments or feedback, easiest way to catch me nowdays is by email or in fediverse where I’m


Subscribe to the comments RSS feed.

Leave Comment

Note to Verbose Commenters
If you can't fit everything you want to say in the comment below then you really should record a response show instead.

Note to Spammers
All comments are moderated. All links are checked by humans. We strip out all html. Feel free to record a show about yourself, or your industry, or any other topic we may find interesting. We also check shows for spam :).

Provide feedback
Your Name/Handle:
Anti Spam Question: What does the letter P in HPR stand for?
Are you a spammer?
What is the HOST_ID for the host of this show?
What does HPR mean to you?