CS 3500 Lecture 2: Function Definitions Pt. 1

68 views2 pages

Document Summary

Definitions of functions in haskell pt. 1 fst :: (a,b) -> a fst (x,y) = x. Ii. snd :: (a,b) -> b snd (x,y) = y. Iii. curry converts an uncurried function to a curried function: curry :: ((a, b) -> c) -> a -> b -> c curry f x y = f (x, y) | otherwise = until p f (f x) Vi. error stops execution and displays an error message: error :: string -> a error = primerror. Map: map :: (a -> b) -> [a] -> [b] map f [] = [] map f (x:xs) = f x : map f xs. Filter: filters unwanted elements out of a list of elements in haskell. 10/22/2017: filter :: (a -> bool) -> [a] -> [a] filter p [] = [] filter p (x:xs) | p x = x : filter p xs.

Get access

Grade+20% off
$8 USD/m$10 USD/m
Billed $96 USD annually
Grade+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
40 Verified Answers
Class+
$8 USD/m
Billed $96 USD annually
Class+
Homework Help
Study Guides
Textbook Solutions
Class Notes
Textbook Notes
Booster Class
30 Verified Answers

Related Documents