Sei sulla pagina 1di 5

Kdata MyNat = O | S MyNat deriving Show

add :: MyNat -> MyNat -> MyNat


add O x = x
add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x
add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x

add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x
add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x
add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x
add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x
add ( 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:_) = x

elementAt i (_:xs) = elementAt (i-1) xs


data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x
add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show
size::MyList -> Int
size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 -> MyNat
add O x = x
add ( 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:_) = x
elementAt i (_:xs) = elementAt (i-1) xs
data MyList a = Null | Cons a ( MyList a ) deriving Show

size::MyList -> Int


size Null = 0
size ( Cons x xs ) = 1 + ( size xs )
getFirst::MyList a -> a
getFirst 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 )

Potrebbero piacerti anche