Skip to content

js-fun/purescript-by-example

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Notes

Chapter 05

  • row polymorphism
> let showPerson { first: x, last: y } = y ++ ", " ++ x

> :type showPerson
forall r. { first :: String, last :: String | r } -> String

-- What is the type variable r here? Well, if we try showPerson in PSCi, we see something interesting:
-- We can read the new type signature of showPerson as “takes any record with first and last fields
-- which are Strings and any other fields, and returns a String”.
-- This function is polymorphic in the row r of record fields, hence the name row polymorphism.

> showPerson { first: "Phil", last: "Freeman" }
"Freeman, Phil"

> showPerson { first: "Phil", last: "Freeman", location: "Los Angeles" }
"Freeman, Phil"

questions

  • how to derive type class

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published