Created
January 2, 2019 14:30
-
-
Save DonaldKellett/e28507a0d0de46d8a61e1277ad1e6199 to your computer and use it in GitHub Desktop.
PureScript by Example - 6.4 Common Type Classes - Exercise 1 Solution
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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