Created
January 2, 2019 09:16
-
-
Save DonaldKellett/79258bbaf78255e3ccc87479caa29a29 to your computer and use it in GitHub Desktop.
PureScript by Example - 5.9 Named Patterns - Exercise 1,3 Solutions
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 NamedPatterns where | |
import Prelude | |
-- Boilerplate code provided in 5.8 Nested Patterns of PureScript by Example | |
type Address = { street :: String, city :: String } | |
type Person = { name :: String, address :: Address } | |
-- Exercise 1 | |
sameCity :: Person -> Person -> Boolean | |
sameCity { address: { city: x } } { address: { city: y } } = x == y | |
-- Exercise 3 | |
fromSingleton :: forall a. a -> Array a -> a | |
fromSingleton _ [x] = x | |
fromSingleton x _ = x |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment