Last active
August 29, 2015 13:57
-
-
Save syntacticsugar/9451705 to your computer and use it in GitHub Desktop.
This file contains 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
import Either | |
--main = asText (filterrr (\x -> x > 2) [1, 2, 3, 4]) | |
main = asText (map squirtWithError [-2, -1, 0, 16, 36]) | |
-- types | |
data Option a = None | Some a | |
-- Option String = None | Some String | |
-- Option Int = None | Some Int | |
-- Option [Int] = None | Some [Int] | |
-- Some 3 => [3] : has type Option Int | |
-- None => [] : Option a (a is a wildcard) | |
-- Some "foo" => ["foo"] : has type Option String | |
data TwoChoices a b = First a | Second b | |
type IntString = TwoChoices Int String | |
a = First 10 | |
b = Second "hello" | |
mixedList = [First 10, Second "Romy", First 0, First 2] | |
sandwich = [Second "jelly", Second "bread", Second "peanut butter"] | |
-- use Either String Number, to store error messages | |
-- for failed computation | |
squirtWithError x = | |
if x < 0 | |
then Either.Left "No negatives you doofus!" | |
else Either.Right (sqrt x) | |
-- functions and recursion | |
sqqquare : Int -> Int | |
sqqquare x = x * x | |
lennngth xs = | |
case xs of | |
[] -> 0 | |
(x::rest) -> 1 + (lennngth rest) | |
mappp : (a -> b) -> [a] -> [b] | |
mappp funccc xs = | |
case xs of | |
Auto-update:Hints:Options: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment