A type is a set of values.
Int -- The set of all integer values (that fit into 64 bits)
To say that a term a
has type A
is to say that a
is a member of the set of values represented by A
.
A type is a set of values. A value stores information at runtime in computer memory (such as a certain integer, a certain list of strings, etc.).
In many languages, functions are values (Haskell, PureScript, Javascript)! Or at least, you can pretend they are (Scala, Java).
These exercises were part of a LambdaConf Outpost meetup. You may find the instructions here.
Develop a model for boolean values (Bool
), which may be either true or false.
Think: Do you need an if-then-else construct? Why or why not?
Bonus: Develop a model for eithers (Either
), whih can be one thing ("left") or another ("right"), and model a boolean as a partitioning of a set into two disjoint sets.
Develop a model for optional values (Maybe
/ Option
), which are containers that are either empty ("nothing" / "none") or hold a single value ("just" / "some").
Develop a model for boolean values (Bool
), which may be either true or false.
Think: Do you need an if-then-else construct? Why or why not?
Bonus: Develop a model for eithers (Either
), whih can be one thing ("left") or another ("right"), and model a boolean as a partitioning of a set into two disjoint sets.
type Bool = forall a. a -> a -> a
_true :: Bool
Copyright © 2016-2018 Fantasyland Institute of Learning. All rights reserved.
A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.
val square : Int => Int = x => x * x
// compound growth calculator | |
val principal = 25000 | |
val rate = 0.01 | |
val n = 1 | |
val t = 20 | |
val total = principal * Math.pow(1 + (rate/n), n*t) | |
println(total) |
#!/usr/bin/ruby | |
#url labels can only be /a-zA-Z0-9-/ | |
urls = [ | |
['Spreedemo-home', 'http://demo.spreecommerce.com/'], | |
['Spreedemo-product', 'http://demo.spreecommerce.com/products/xm-inno-xm2go-portable-satellite-radio-mp3-player-and-home-kit'], | |
['Google-home', 'http://www.google.com/'], | |
['Google-shopping', 'http://www.google.com/prdhp?hl=en&tab=vf'] | |
] | |
n = 100 |