feb10 - first :: [a] -> a first = error "first:...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
list1 :: [Int] list1 = [ 14, 16, 18, -1] list2 :: [Bool] list2 = [False, True, True] list3 :: [Char] list3 = [ 'a', 'A', '1', 'y', 'M'] list4 :: [(Char, Int)] list4 = [('a',1), ('b', 12), ('c', -3)] divisors :: Integer -> [Integer] divisors n = [ x | x <- [1 . . n], n `mod` x == 0 ] prime :: Integer -> Bool prime n = (n> 1) && ([1, n] == divisors n) -- return first item in list
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: first :: [a] -> a first = error "first: can't accept empty list as input"-- first (x:xs) = x first (x:_) = x mystery :: [a] -> Int mystery (x:y:zs) = 2 mystery (x:xs) = 1 mystery _ = 0 mystery2 :: [a] -> [a] mystery2 (x:y:zs) = [y] mystery2 (x:xs) = [x] mystery2 _ = myLength :: [a] -> Int myLength = 0 myLength (x:xs) = 1 + myLength xs...
View Full Document

This note was uploaded on 02/14/2011 for the course CIS 252 taught by Professor Staff during the Spring '08 term at Syracuse.

Ask a homework question - tutors are online