U
U
ukh2019-12-14 21:07:18
Haskell
ukh, 2019-12-14 21:07:18

How to make the following Haskell functions?

Urgently need help!!! Who can help please!!
Date data:
data B = T | F deriving Show
data Nat = Zero | S Nat
data ZInt = Z Nat Nat
deriving Show
a) Do the following functions:
oddN :: Nat -> B
fibonacci :: Nat -> Nat
isTeilerN :: Nat -> Nat -> B -- checks if the first number is divisible by the second
ggtN :: Nat -> Nat -> Nat -- greatest common divisor
b) Program the following functions (only the Error Haskell function is allowed if needed):
(<<<) :: ZInt -> ZInt -> B -- checks if less than first number of second
maxZ :: ZInt -> ZInt -> ZInt
multZ :: ZInt -> ZInt -> ZInt
absZ :: ZInt -> ZInt -- absolute value of a number
powZ :: ZInt -> Nat -> ZInt --
exponent isTeilerZ :: ZInt -> ZInt -> B -- checks if the first number is divisible by the second
ggtZ :: ZInt - > ZInt -> ZInt -- greatest common divisor
d) Make helper functions zint2Int and int2ZInt that make it easier to test the ZInt functions. You can use built-in functions in Haskell
Example
zint2Int (Z (S (S (S Zero))) Zero) => 3
int2ZInt 5 => Z 5 0
int2ZInt 5 => Z (S (S (S (S (S Zero)) ))) Zero
int2ZInt (-5) => 5

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
akkakk, 2019-12-15
@akkakk

Hmm, every time I sit here and wonder what Esponda smokes

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question