Skip to content

Instantly share code, notes, and snippets.

@DonaldKellett
Created January 2, 2019 09:16
Show Gist options
  • Save DonaldKellett/79258bbaf78255e3ccc87479caa29a29 to your computer and use it in GitHub Desktop.
Save DonaldKellett/79258bbaf78255e3ccc87479caa29a29 to your computer and use it in GitHub Desktop.
PureScript by Example - 5.9 Named Patterns - Exercise 1,3 Solutions
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