Please describe the input and output of the functions zip and unzip in Haskell functional language. What are their type signatures?
INPUT OUTPUT IN HASKELL
The monadic I/O system used in Haskell is described by the Haskell language report. Commonly used I/O functions such as print are part of the standard prelude and need not be explicitly imported. This library contain more advanced I/O features. Some related operations on file systems are contained in the Directory library.
module IO (
Handle, HandlePosn,
IOMode(ReadMode,WriteMode,AppendMode,ReadWriteMode),
BufferMode(NoBuffering,LineBuffering,BlockBuffering),
SeekMode(AbsoluteSeek,RelativeSeek,SeekFromEnd),
stdin, stdout, stderr,
openFile, hClose, hFileSize, hIsEOF, isEOF,
hSetBuffering, hGetBuffering, hFlush,
hGetPosn, hSetPosn, hSeek,
hWaitForInput, hReady, hGetChar, hGetLine, hLookAhead, hGetContents,
hPutChar, hPutStr, hPutStrLn, hPrint,
hIsOpen, hIsClosed, hIsReadable, hIsWritable, hIsSeekable,
isAlreadyExistsError, isDoesNotExistError, isAlreadyInUseError,
isFullError, isEOFError,
isIllegalOperation, isPermissionError, isUserError,
ioeGetErrorString, ioeGetHandle, ioeGetFileName,
try, bracket, bracket_
-- ...and what the Prelude exports
IO, FilePath, IOError, ioError, userError, catch, interact,
putChar, putStr, putStrLn, print, getChar, getLine, getContents,
readFile, writeFile, appendFile, readIO, readLn
) where
import Ix(Ix)
data Handle = ... -- implementation-dependent
instance Eq Handle where ...
instance Show Handle where .. -- implementation-dependent
data HandlePosn = ... -- implementation-dependent
instance Eq HandlePosn where ...
instance Show HandlePosn where --- -- implementation-dependent
data IOMode = ReadMode | WriteMode | AppendMode | ReadWriteMode
deriving (Eq, Ord, Ix, Bounded, Enum, Read, Show)
data BufferMode = NoBuffering | LineBuffering
| BlockBuffering (Maybe Int)
deriving (Eq, Ord, Read, Show)
data SeekMode = AbsoluteSeek | RelativeSeek | SeekFromEnd
deriving (Eq, Ord, Ix, Bounded, Enum, Read, Show)
stdin, stdout, stderr :: Handle
openFile :: FilePath -> IOMode -> IO Handle
hClose :: Handle -> IO ()
hFileSize :: Handle -> IO Integer
hIsEOF :: Handle -> IO Bool
isEOF :: IO Bool
isEOF = hIsEOF stdin
hSetBuffering :: Handle -> BufferMode -> IO ()
hGetBuffering :: Handle -> IO BufferMode
hFlush :: Handle -> IO ()
hGetPosn :: Handle -> IO HandlePosn
hSetPosn :: HandlePosn -> IO ()
hSeek :: Handle -> SeekMode -> Integer -> IO ()
hWaitForInput :: Handle -> Int -> IO Bool
hReady :: Handle -> IO Bool
hReady h = hWaitForInput h 0
hGetChar :: Handle -> IO Char
hGetLine :: Handle -> IO String
hLookAhead :: Handle -> IO Char
hGetContents :: Handle -> IO String
hPutChar :: Handle -> Char -> IO ()
hPutStr :: Handle -> String -> IO ()
hPutStrLn :: Handle -> String -> IO ()
hPrint :: Show a => Handle -> a -> IO ()
hIsOpen :: Handle -> IO Bool
hIsClosed :: Handle -> IO Bool
hIsReadable :: Handle -> IO Bool
hIsWritable :: Handle -> IO Bool
hIsSeekable :: Handle -> IO Bool
isAlreadyExistsError :: IOError -> Bool
isDoesNotExistError :: IOError -> Bool
isAlreadyInUseError :: IOError -> Bool
isFullError :: IOError -> Bool
isEOFError :: IOError -> Bool
isIllegalOperation :: IOError -> Bool
isPermissionError :: IOError -> Bool
isUserError :: IOError -> Bool
ioeGetErrorString :: IOError -> String
ioeGetHandle :: IOError -> Maybe Handle
ioeGetFileName :: IOError -> Maybe FilePath
try :: IO a -> Either IOError a
bracket :: IO a -> (a -> IO b) -> (a -> IO c) -> IO c
bracket_ :: IO a -> (a -> IO b) -> IO c -> IO c
INPUT OUTPUT EXPLAINED USING PRELUDE FUNCTION
In this appendix the entire Haskell Prelude is given. It constitutes a specification for the Prelude. Many of the definitions are written with clarity rather than efficiency in mind, and it is not required that the specification be implemented as shown here.
The Prelude shown here is organized into a root module, Prelude, and three sub-modules, PreludeList, PreludeText, and PreludeIO. This structure is purely presentational. An implementation is not required to use this organisation for the Prelude, nor are these three modules available for import separately. Only the exports of module Prelude are significant.
Some of these modules import Library modules, such as Char, Monad, IO, and Numeric. These modules are described fully in the accompanying Haskell 98 Library Report. These imports are not, of course, part of the specification of the Prelude. That is, an implementation is free to import more, or less, of the Library modules, as it pleases.
Primitives that are not definable in Haskell , indicated by names starting with "prim", are defined in a system dependent manner in module PreludeBuiltin and are not shown here. Instance declarations that simply bind primitives to class methods are omitted. Some of the more verbose instances with obvious functionality have been left out for the sake of brevity.
Declarations for special types such as Integer, (), or (->) are included in the Prelude for completeness even though the declaration may be incomplete or syntactically invalid.
module Prelude (
module PreludeList, module PreludeText, module PreludeIO,
Bool(False, True),
Maybe(Nothing, Just),
Either(Left, Right),
Ordering(LT, EQ, GT),
Char, String, Int, Integer, Float, Double, Rational, IO,
-- List type: []((:), [])
-- Tuple types: (,), (,,), etc.
-- Trivial type: ()
-- Functions: (->)
Eq((==), (/=)),
Ord(compare, (<), (<=), (>=), (>), max, min),
Enum(succ, pred, toEnum, fromEnum, enumFrom, enumFromThen,
enumFromTo, enumFromThenTo),
Bounded(minBound, maxBound),
Num((+), (-), (*), negate, abs, signum, fromInteger),
Real(toRational),
Integral(quot, rem, div, mod, quotRem, divMod, toInteger),
Fractional((/), recip, fromRational),
Floating(pi, exp, log, sqrt, (**), logBase, sin, cos, tan,
asin, acos, atan, sinh, cosh, tanh, asinh, acosh, atanh),
RealFrac(properFraction, truncate, round, ceiling, floor),
RealFloat(floatRadix, floatDigits, floatRange, decodeFloat,
encodeFloat, exponent, significand, scaleFloat, isNaN,
isInfinite, isDenormalized, isIEEE, isNegativeZero, atan2),
Monad((>>=), (>>), return, fail),
Functor(fmap),
mapM, mapM_, sequence, sequence_, (=<<),
maybe, either,
(&&), (||), not, otherwise,
subtract, even, odd, gcd, lcm, (^), (^^),
fromIntegral, realToFrac,
fst, snd, curry, uncurry, id, const, (.), flip, ($), until,
asTypeOf, error, undefined,
seq, ($!)
) where
import PreludeBuiltin -- Contains all `prim' values
import PreludeList
import PreludeText
import PreludeIO
import Ratio( Rational )
infixr 9 .
infixr 8 ^, ^^, **
infixl 7 *, /, `quot`, `rem`, `div`, `mod`
infixl 6 +, -
infixr 5 :
infix 4 ==, /=, <, <=, >=, >
infixr 3 &&
infixr 2 ||
infixl 1 >>, >>=
infixr 1 =<<
infixr 0 $, $!, `seq`
module PreludeList (
map, (++), filter, concat,
head, last, tail, init, null, length, (!!),
foldl, foldl1, scanl, scanl1, foldr, foldr1, scanr, scanr1,
iterate, repeat, replicate, cycle,
take, drop, splitAt, takeWhile, dropWhile, span, break,
lines, words, unlines, unwords, reverse, and, or,
any, all, elem, notElem, lookup,
Sum, product, maximum, minimum, concatMap,
zip, zip3, zipWith, zipWith3, unzip, unzip3)
where
import qualified Char(isSpace)
infixl 9 !!
infixr 5 ++
infix 4 `elem`, `notElem`
module PreludeText (
ReadS, ShowS,
Read(readsPrec, readList),
Show(showsPrec, showList),
reads, shows, show, read, lex,
showChar, showString, readParen, showParen ) where
-- The instances of Read and Show for
-- Bool, Char, Maybe, Either, Ordering
-- are done via "deriving" clauses in Prelude.hs
import Char(isSpace, isAlpha, isDigit, isAlphaNum,
showLitChar, readLitChar, lexLitChar)
import Numeric(showSigned, showInt, readSigned, readDec, showFloat,
readFloat, lexDigits)
module PreludeIO (
FilePath, IOError, ioError, userError, catch,
putChar, putStr, putStrLn, print,
getChar, getLine, getContents, interact,
readFile, writeFile, appendFile, readIO, readLn
) where
import PreludeBuiltin
Example of zip:
1.Input: zip [1,2,3] [9,8,7]
Output: [(1,9),(2,8),(3,7)]
2.Input: zip (take 5 (iterate (2*) 10)) (take 5 (iterate (2/) 10))
Output: [(10,10.0),(20,0.2),(40,10.0),(80,0.2),(160,10.0)]
Example of unzip:
1.Input: unzip [(1,2),(2,3),(3,4)]
Output: ([1,2,3],[2,3,4])
Please describe the input and output of the functions zip and unzip in Haskell functional language....
Please write below functions in HASKELL functional programming language and remember to include both the (1) function declaration, and (2) function definition. 1. Write a function sumLastPart which, only using library functions, returns the sum of the last n numbers in the list, where n is the first argument to the function. sumLastPart :: Int -> [Int] -> Int
Two important functions that convert pairlists to pairs of lists and vice versa are Zip and UnZip. a) Implement a function Zip that takes a pair Xs#Ys of two lists Xs and Ys (of the same length) and returns a pairlist, where the first field of each pair is taken from Xs and the second from Ys. For example, {Zip [a b c]#[1 2 3]} returns the pairlist [a#1 b#2 c#3]. The function UnZip does the inverse, for example {UnZip [a#1...
Briefly explain why the head function is not considered “safe” in Haskell functional programming language.
Haskell Functional Programming Language: Write a function nestedParens that takes a string argument and returns true if it is a nesting of zero or more pairs of parentheses, e.g. "((()))" should return True ; "()()" or "(()))" should return False . Use recursion for this problem. nestedParens :: String -> Bool
I need only one C++ function . It's C++ don't
write any other language.
Hello I need unzip function here is my zip function
below. So I need the opposite function unzip.
Instructions:
The next tools you will build come in a pair, because
one (zip) is a file compression tool, and
the other (unzip) is a file decompression
tool.
The type of compression used here is a simple form of
compression called run-length encoding (RLE). RLE is quite simple:
when...
I need only one C++ function . It's C++ don't write any other language. Hello I need unzip function here is my zip function below. So I need the opposite function unzip. Instructions: The next tools you will build come in a pair, because one (zip) is a file compression tool, and the other (unzip) is a file decompression tool. The type of compression used here is a simple form of compression called run-length encoding (RLE). RLE is quite simple: when...
Please write clearly and if possible step by step,Take the input as ???(?) and the output as ????(?), and find transfer functions of the electrical
circuits below.Thanks a lot!
Please write clearly and if possible step by step,Take the input as ???(?) and the output as ????(?), and find transfer functions of the electrical circuits below,Thanks a lot!
PLEASE HELP ASAP Write a 8088 assembly language program to accept input expressions from standard input consisting of an integer, an operator, and another integer and output the value of the expression to standard output. Valid operators are +, -, x and/ for addition, subtraction, multiplication and division respectively.
In C Programming Language, write a program Character Pointers and Functions. Keyboard input to enter one character string. Using a single dimension array, populate the array with the character string, call a function using pointers to reverse order the character string, pass back to the main the output and total_count_of_characters. (maybe use a global variable for the total count). Print display the reversed char string and total_count.