Clock

Clock

Medium

Instructions

Implement a clock that handles times without dates.

You should be able to add and subtract minutes to it.

Two clocks that represent the same time should be equal to each other.

It's a 24 hour clock going from "00:00" to "23:59".

To complete this exercise you need to define the data type Clock, add an Eq instance, and implement the functions:

  • addDelta
  • fromHourMin
  • toString

addDelta adds a duration, expressed in hours and minutes, to a given time, represented by an instance of Clock.

fromHourMin takes an hour and minute, and returns an instance of Clock with those hours and minutes.

toString takes an instance of Clock and returns a string representation of the clock, in 0-padded format like "08:03" or "22:35"

You will find a dummy data declaration and type signatures already in place, but it is up to you to define the functions and create a meaningful data type, newtype or type synonym.

If you need help getting started with types, take a look at:

Edit via GitHub The link opens in a new window or tab
Haskell Exercism

Ready to start Clock?

Sign up to Exercism to learn and master Haskell with 103 exercises, and real human mentoring, all for free.