HOMEWORK #3 Task 1: Numbers and arithmetic. Task 2: Booleans and comparison. Task 3: Operators. Task 4: Strings and slices. Task 5: Lists and folds. Task 6: Bytes and serialisation. Task 7: File I/O. Task 8: Date and time. Task 9: Random numbers. Task 10: Short-circuit evaluation. Task 11: Dictionaries
Лабораторная работа
в среде программирования Haskell
Среда программирования: Haskell
Название работы: HOMEWORK #3 Task 1: Numbers and arithmetic. Task 2: Booleans and comparison. Task 3: Operators. Task 4: Strings and slices. Task 5: Lists and folds. Task 6: Bytes and serialisation. Task 7: File I/O. Task 8: Date and time. Task 9: Random numbers. Task 10: Short-circuit evaluation. Task 11: Dictionaries
Вид работы: Лабораторная работа
Описание: Лабораторная работа на языке Haskell.
Условия задания в прикрепленном файле.
HOMEWORK #3
In this homework we will gradually develop a small programming language called Hi.
Project Structure
Create a .cabal file with both a library and an executable:
library
exposed-modules: ...
build-depends: ...
...
executable hi
main-is: Main.hs
hs-source-dirs: ...
build-depends: ...
...
In the library component, create the following modules:
HW3.Base
HW3.Parser
HW3.Pretty
HW3.Evaluator
You are allowed to add more modules to the project, but those are the required ones.
In HW3.Base, define the following data types:
data HiFun -- function names (e.g. div, sort, length, ...)
data HiValue -- values (numbers, booleans, strings, ...)
data HiExpr -- expressions (literals, function calls, ...)
data HiError -- evaluation errors (invalid arguments, ...)
In each task, we will add constructors to these data types that are needed to implement
new language features.
In HW3.Parser, define the following function:
parse :: String -> Either (ParseErrorBundle String Void) HiExpr
The ParseErrorBundle type comes from the megaparsec package which we will use
to implement our parser.
In HW3.Pretty, define the following function:
prettyValue :: HiValue -> Doc AnsiStyle
The Doc and AnsiStyle types come from the prettyprinter and prettyprinteransi-terminal packages respectively. This function renders a value to a document,
which in turn can be either printed to the terminal (with color highlighting) or
converted to a string.
In HW3.Evaluator, define the following function:
eval :: Monad m => HiExpr -> m (Either HiError HiValue)
One might wonder why we need the Monad m part. Indeed, for arithmetic operations, a
simpler type would be sufficient:
eval :: HiExpr -> Either HiError HiValue
However, the monadic context will come into play later, when we start implementing
IO actions (file system access, random number generation, and so on).
The executable component consists just of a single file, Main.hs.
The REPL
Using the haskeline package, implement a REPL in Main.hs that uses parse, eval, and
prettyValue defined above. It’s going to be just 15–20 lines of code, but you will use it all
the time to test your implementation.
Here’s an example session that will become possible as soon as we implement arithmetic
operations:
hi> mul(2, 10)
20
hi> sub(1000, 7)
993
hi> div(3, 5)
0.6
Task 1: Numbers and arithmetic
Task 2: Booleans and comparison
Task 3: Operators
Task 4: Strings and slices
Task 5: Lists and folds
Task 6: Bytes and serialisation
Task 7: File I/O
Task 8: Date and time
Task 9: Random numbers
Task 10: Short-circuit evaluation
Task 11: Dictionaries
Год: 2021
Данный заказ (лабораторная работа) выполнялся нашим сайтом в 2021-м году, в рамках этого заказа была разработана программа в среде программирования Haskell. Если у Вас похожее задание на программу, которую нужно написать на Haskell, либо на другом языке программирования, пожалуйста заполните форму, приведённую ниже, после чего Ваше задание в первую очередь рассмотрит наш программист, выполнявший в 2021-м году этот заказ, если он откажется, то Ваше задание оценят другие наши программисты в течение 48-и часов, если оценка нужна срочно, просим Вас оставить пометку об этом - напишите в тексте задания фразу "СРОЧНЫЙ ЗАКАЗ".
Тел.:
+79374242235
Viber: +79374242235 Telegram: kursovikcom ВКонтакте: kursovikcom WhatsApp +79374242235 E-mail: info@kursovik.com Skype: kursovik.com |