8/16/2019 hfebve hefv
1/5
Kdata MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = xadd ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = xadd ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> a
elementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0
getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = x
8/16/2019 hfebve hefv
2/5
add ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 )
| odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = xadd ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]
chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = xadd ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
8/16/2019 hfebve hefv
3/5
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = x
add ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = xadd ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = x
8/16/2019 hfebve hefv
4/5
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = xadd ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )data MyNat = O | S MyNat deriving Show
add :: MyNat -> MyNat -> MyNatadd O x = xadd ( S x ) y = S ( add x y )
data Option a = None | Some a deriving Show
elementAt :: Int -> [a] -> aelementAt i l | (i < 0) || i >= (length l) = error "Index out of bounds."elementAt 0 (x:_) = xelementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
8/16/2019 hfebve hefv
5/5
size::MyList -> Intsize Null = 0size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> agetFirst Null = 0getFirst ( Cons x xs ) = x
chain::(Integral a)=> a -> [a]chain 1 = [1] | even n = n:chain ( n `div` 2 ) | odd n = n:chain ( n*3+1 )
Recommended