Skip to content

Instantly share code, notes, and snippets.

@DonaldKellett
Created January 2, 2019 14:30
Show Gist options
  • Save DonaldKellett/e28507a0d0de46d8a61e1277ad1e6199 to your computer and use it in GitHub Desktop.
Save DonaldKellett/e28507a0d0de46d8a61e1277ad1e6199 to your computer and use it in GitHub Desktop.
PureScript by Example - 6.4 Common Type Classes - Exercise 1 Solution
module CommonTypeClasses where
import Prelude
-- Boilerplate code
newtype Complex = Complex
{ real :: Number
, imaginary :: Number
}
-- Exercise 1
instance showComplex :: Show Complex where
show (Complex { real, imaginary }) =
"Complex (" <> show real <> ", " <> show imaginary <> ")"
instance eqComplex :: Eq Complex where
eq (Complex { real, imaginary }) (Complex { real: real', imaginary: imaginary' }) =
real == real' && imaginary == imaginary'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment