tutorbin

haskell programming homework help

Boost your journey with 24/7 access to skilled experts, offering unmatched haskell programming homework help

tutorbin

Trusted by 1.1 M+ Happy Students

WhatsApp Support

Get Instant
Online Homework Help
via WhatsApp

Get instant homework help from top tutors—just a WhatsApp message away. 24/7 hw help support for all your academic needs!

A
S
M
R
★★★★★
2M+ students trust TutorBin
Your WhatsApp Number
phone
or
⚡ Instant reply
🔒 100% private
👨‍🏫 Top tutors
🌍 All subjects
*Get instant homework help from top tutors—just a WhatsApp message away. 24/7 support for all your academic needs!
2M+ Students Helped24/7 Live SupportExpert TutorsAll Subjects CoveredInstant Response100% ConfidentialTop Rated ServiceMoney-back Guarantee2M+ Students Helped24/7 Live SupportExpert TutorsAll Subjects CoveredInstant Response100% ConfidentialTop Rated ServiceMoney-back Guarantee

Recently Asked haskell programming Questions

Expert help when you need it
  • Q1:1. a)Write a program that allows a user to select a number between 1 and 5 and then prints a famous quote (quotes are of your choosing). After printing the quote, the program will ask whether the user would like another. If the user enters n, the program ends; otherwise, the user gets another quote. The program repeats until the user enters n. Try to use lazy evaluation and treat the user input as a list rather than recursively calling main at the end. b) The following Haskell functions each take predicate function and a list as input and remove certain items from the list based on the predicate function. They each have this signature: (a -> Bool) -> [a] -> [a] a. 1trim removes all items from the start of the list that satisfy the predicate function. b. rtrim removes all items from the end of the list that satisfy the predicate function. c. trim removes all items from both the start and end of the list that satisfy the predicate function. Implement these functions and demonstrate the result.See Answer
  • Q2:2. Using Haskell: a)Write a function rotabc that changes a's to b's, b's to c's and c's to a's in a string. Only lowercase letters are affected. b) Implement a Haskell function that deletes the first occurrence of an element from a list. c) Write a function in Haskell that times execution of a function. d) Write a function in Haskell that formats the time of daySee Answer
  • Q3:Implementation, Test File and Report In addition to your solutions to these programming challenges, you are asked to submit an additional Tests.hs file with your own tests, and a report: You are expected to test your code carefully before submitting it and we ask that you write a report on your development strategy. Your report should include an explanation of how you implemented and tested your solutions. Your report should be up to 1 page (400 words). Note that this report is not expected to explain how your code works, as this should be evident from your commented code itself. Instead you should cover the development and testing tools and techniques you used, and comment on their effectiveness. Your report should include a second page with a bibliography listing the source(s) for any fragments of code written by other people that you have adapted or included directly in your submission. Submission and Marking Your Haskell solutions should be submitted as a single plain text file Challenges.hs. Your tests should also be submitted as a plain text file Tests.hs that includes a main function. Finally, your report should be submitted as a PDF file, Report.pdf. The marking scheme is given in the appendix below. There are up to 5 marks for your solution to each of the programming challenges, up to 5 for your explanation of how you implemented and tested these, and up to 5 for your coding style. This gives a maximum of 40 marks for this assignment, which is worth 40% of the module. Your solutions to these challenges will be subject to automated testing so it is important that you adhere to the type definitions and type signatures given in the supplied dummy code file Challenges.hs. Do not change the list of functions and types exported by this file. Your code will be run using a command line such as stack ghc -e "main" CW2Tests.hs, where CW2Tests.hs imports Challenge.hs. You should check before you submit that your solution compiles and runs as expected. The supplied Parsing.hs file will be present so it is safe to import this and any library included in the standard Haskell distribution (Version 7.6.3). Third party libraries will not be present so do not import these. Your own test cases in the submitted file Tests.hs will also be run using a similar command line, so make sure this file defines a suitable main function that runs your tests and reports the results.See Answer
  • Q4:5.1 Submission For submission, you must submit three files (slip.hs, tests.slip, and rapport.tex) through the Moodle (also known as StudiUM) page of the course. Make sure the report compiles correctly on ens.iro (which you can connect to via SSH). 6 Details - The grade will be divided as follows: 25% for the report, 60% for the code (divided between s21, hinsert, and eval), and 15% for the tests. - Any use of material (code or text) borrowed from someone else (found on the web,...) must be properly cited, otherwise it will be considered as plagiarism. - The code must in no case exceed 80 columns. - Check the course web page for any errata, and other additional instructions. - The grade is based on two parts: automatic tests, reading of the code, and the report. The most important criterion is that your code should behave correctly. Next comes the quality of the code: the simpler, the better. If there are many comments, it is usually a sign that the code is not clear; but of course,See Answer
  • Q5:3. The Y combinator: The following famous term is called the Y combinator. Y=At. (Art (22)) (Az.t (22)) This term looks almost like the self-application of sa, but it is different in that it involves an additional function t in a subtle way. Consider an application Yt and let us see what we can learn about it using 3-reduction: Yt = (Az.t (z)) (Az.t (22)) ((Art (12)) (Art (22))) by 3-reduction noticing that the inner term is Yt t(Yt) So, Yt is equal to the function t applied to itself! One can use this to repeatedly unfold Yt. Yt=t(Yt)=t(t (Yt)) = t (t (t (Yt))) = --- This might seem like another form of an infinite loop, but it is actually quite useful. In fact, it is used to encode recursive functions in the lambda calculus. Consider the recursive definition of a function such as the factorial: define factorial = An. if (=n 1) 1 (*n (factorial (-1)) On the surface, this is a circular definition and cannot be expressed in lambda calculus. To resolve the difficulty, we first treat the right hand side of the definition as a function of "factorial": define define factorial = T factorial T=Af. An. if (n1)1 (*n (f(-1)) The definition of T is quite normal, but the first line is still a circular definition. However, this is exactly the kind of circularity that the Y combinator allows us to capture. The Y combinator satisfies the equality YT=T(YT). So, we can just say that factorial is YT and we get what we want without any circular definitions. Does this actually work? Here is a sample calculation: (YZ) 2 (YT) 1See Answer
  • Q6: TP #1 IFT-2035 1 Overview This lab aims to improve the understanding of functional programming by using a functional programming language (Haskell) and writing a part of an interpreter for a functional programming language (in this case a kind of Lisp). The steps of this work are the following: 1. Improve your knowledge of Haskell. 2. Read and understand this data. This will probably take a significant portion of the total time. 3. Read, find, and understand the important parts of the provided code. 4. Complete the provided code. 5. Write a report. It should describe your experience during the previous points: problems encountered, surprises, choices you had to make, options you consciously rejected, etc. The report should not exceed 5 pages. This work is to be done in groups of two. The report, in LATEX format only (compilable on ens.iro) and the code are to be submitted by electronic submission before the indicated date. No delay will be accepted. Clearly indicate your name at the beginning of each file. Those who want to do this work alone must first obtain permission, and the evaluation of their work will not take it into account. Groups of 3 or more are excluded. e ::= n |x | (Axe) | (e0 e1 ... en) | (ref! e) |(get ! e) | (set! e1 e2) |+| - | * |/ Signed Decimal Integer A variable A function with an argument A curried function call Construction of a ref-cell Find the value of the ref-cell e Change the value of the ref-cell e1 Predefined arithmetical operations |< | > | = | <= | >= Boolean operations on integers | (if e1 e2 e3) If e1 then e2 else e3 |(let x e1 e2) Simple local declaration | (letrec ((x1 e1) ... (xn en)) e) Recursive local declarations Fig 1. Slip syntax 2 Slip: A kind of Lisp In this project, you will work on the implementation of a functional language whose syntax is inspired by the Lisp language. The syntax of this language is described in Figure 1. It is important to note that, as always with Lisp-style syntax, parentheses are significant. The let form is used to give a name to a non-recursive local definition. The letrec form is a more complex variant that allows for multiple simultaneous local definitions, which can also be recursive, including mutually recursive, as in the Haskell let. 2.1 Dynamic semantics Slip, like Lisp, is a dynamically typed language, meaning that its variables can contain values of any type. There is therefore no static semantics (typing rules). The values manipulated at runtime by our language are integers, functions, booleans, and references that point to ref-cells, which are memory cells whose contents can be modified (the rest of the values manipulated by Slip are immutable). A ref-cell is constructed with ref!(), which takes the initial value of the cell as an argument, allocates the cell somewhere in memory, and returns a reference (its address). The current value of the cell can then be retrieved with get!() and the value changed with set!(). (λ p (set! p (+ 1 (get! p)))) is a function that increments a cell by adding 1. The fundamental evaluation rules are as follows: ((Axe) v) (let x v e) هارد e[v/x] e[v/x] (letrec ((1 v1)... (In Un)) e) W e[v1, Un/1,, In] (eg €1 en) (eo) for + ((eo €1)... en) Co Where the notation e[v/x] represents the expression e in an environment where the variable x takes the value v. The use of v in the rules above indicates that it is indeed a value rather than an expression that has not yet been evaluated. For example, the v in the first rule indicates that when calling a function, the argument must be evaluated before entering the body of the function, i.e. we use call by value. In addition to the two ẞ rules above, the different arithmetic primitives behave as expected: ~ mi — m2 - n1—N2 (+ n₁ n₂) (- n₁ n₂) ~ (* n1 n₂) ← n1 x n2 ... So it is a variant of the X-calculus, no big surprise. The scope is static and the order of evaluation is by value. However, the reduction rules below do not take into account the presence of impure operations ref !, get !, and set !, which require the use of more complex reductions where we consider not only the expression to be reduced but also the state of the memory (also sometimes called the heap). More specifically, the rules above have the form ee' but should actually be of the form (M; e)(M; e'). Thus, the impure rules can be defined as follows: (M; (ref! v)) > (M, e 7⇒ v; e) e is a new address ~> (M; (get! )) (M; v) M(e) = v (M; (set ! & v)) ~> (M' ; v) M' = M, e 7 → v Haskell code remains pure and will therefore follow these semantic rules in a fairly straightforward way: the eval function will receive an argument that represents this M which will be modified in a pure way. 3 Implementation The implementation of the language works in several phases: 1. A first phase of lexical and syntactic analysis transforms the source code into a representation described below, called Sexp in the code. This is not yet a complete abstract syntax tree (it actually resembles XML). 2. A second phase, called s21, completes the syntactic analysis and begins compilation, by transforming this tree into a true abstract syntax tree in the representation called Lexp in the code. In a sense, this phase already begins compilation since the Lexp language is not identical to our source language. 3. Finally, an eval function proceeds to the evaluation of the expression by interpretation. A portion of the implementation is already provided: the first phase as well as various pieces of the others. Your task will be to fill in the gaps. 3.1 Lexical and syntactic analysis: Sexp The lexical and syntactic analysis is already implemented for you. It is more permissive than necessary and accepts any expression of the following form: e ::= n | × | '(' {e} )' n is a signed decimal integer. It is represented in the Haskell tree by: Snum n. x is a symbol that can be composed of any number of alphanumeric and/or punctuation characters. For example, '+' is a symbol, '<=' is a symbol, 'voiture' is a symbol, and 'a+b' is also a symbol. In the Haskell tree, a symbol is represented by: Ssym x. '('{e}')' is a list of expressions. In the Haskell tree, lists of expressions are represented by simply linked lists consisting of pairs Scons left right and the end marker Snil. left is the first element of the list and right is the rest of the list. For example, the parser transforms the expression (+ 2 3) into the following Haskell tree: Snode (Ssym "+") [Snum 2, Snum 3] The lexical analyzer considers that a ';' character starts a comment, which ends at the end of the line. 3.2 The Lexp intermediate representation This intermediate representation is a kind of abstract syntax tree. In this representation, +, -, ... are simply predefined variables. 3.3 The execution environment The provided code also defines the initial execution environment, which contains the predefined functions of the language such as addition, subtraction, etc. It is defined as a table that associates to each predefined identifier the value (of type Value) associated. 3.4 Evaluation The evaluator uses the initial environment to reduce an expression (of type Lexp) to a value (of type Value). It also takes an argument that represents the memory state M and which is returned (possibly modified) with the value resulting from the evaluation of the expression.See Answer
  • Q7: COM2108 FUNCTIONAL PROGRAMMING GRADING ASSIGNMENT This is a grading assignment, hence worth 60% of your overall mark if you pass the threshold assessment. The flip side is that if you pass the threshold assessment, you get 40% for the module even if you get 0 on this assignment. The grading assignment deadline is before the later threshold assessment attempt sittings, so you should aim to attempt this assignment even if you have not yet passed the threshold assessment. The work you do on this assignment should improve your understanding of threshold concepts and so help you perform better on the threshold assessment. INTRODUCTION This programming assignment is based around the game of dominos. The first thing to do, if you are not already familiar with the game, is to learn about it. Wikipedia can help you here: http://en.wikipedia.org/wiki/Dominos Here is an example of a dominos board part-way through a game left end right end Board1 . • If the next player has in her hand the following: Hand1 at the left end or Then she may play at the right end of the above board. The other dominos may not be played. Some dominos games allow plays up and down as well as left and right from a double, otherwise known as a "spinner", but we will not allow such moves. A standard set of dominos contains all the permutations from to, 28 in all. There are many variations on the games of dominos and how it is scored. In this assignment you will implement fives-and-threes dominos players (details to follow) and test them against each other by playing simulated matches. Some hints are provided about good play. You should experiment with your dominos players to see if implementing each hint does indeed improve the player's game. You are not expected to program all the hints and you may try other tactics. PLAYING A ROUND OF FIVES-AND-THREES DOMINOS To play a round of fives-and-threes dominos, you proceed as follows: • • • Each player starts with a hand of N dominos. The remaining dominos take no part in this round – they are 'sleeping'. N is usually 7, but a variation of the rules uses 9 dominos if there are only two players. Players add a domino to the board ('dropping' a domino) in turn and accumulate the fives-and-threes scores of their 'drops'. See below for details of how the score is calculated after each drop. The player who drops the first domino gets the fives-and-threes score of its total spots (e.g. if the first drop is which we will represent by (4,5), the player who dropped it scores 3 - full details of how to calculate the score are provided below). If a player does not have a domino that they can play on the current board, they 'knock' to indicate that they are skipping their turn. They cannot knock if they have a domino that they can play. Play continues until neither player can play (either because each player has run out of dominos or is knocking). If a player 'chips out' (plays a domino so that they have no dominos left in their hand) they score one point for this (on top of whatever they score for playing the tile). SCORING FOR Fives-and-THREES DOMINOS After a player has added a domino to the layout, the pips (number of dots) on the two open ends are added up. Points are awarded as follows: Pip total Score Justification 3 1 One 3 5 1 One 5 6 2 Two 3s 9 3 Three 3s 10 2 12 4 15 8 Two 5s Four 3s Five 3s and Three 5s 18 6 Six 3s 20 4 Four 5s Other values 0 Not a multiple of 5 or 3 PLAYING A MATCH OF FIVES-AND-THREES DOMINOS A 2-player fives-and-threes dominos match is organised as follows: A match consists of N games, typically 3 in a real-life setting. The winner is the player who has won most games. With our tireless computer players, N can be much greater than 3. • Each game involves a sequence of rounds (as defined above). The two players take it in turns to drop first in each round. COM2108: Functional Programming - Autumn 2023 2 • A game terminates when one player or the other wins by achieving an accumulated score, over the rounds, of exactly V, where V is the target value. V is typically 61, but a different value can be chosen, such as 31 or 121. At the end of a round, if neither player has reached V, a new round starts, and the scores obtained within this round are added on to the scores after the last round. You must finish exactly, for example if your target is 61 and your score is 59, you need to play a domino which scores 2 to win the game... but if that domino is your last domino, you need to score just 1 from the domino that you play, because you also get a point for “chipping out." If you score more than the target ('going bust'), your score remains the same (e.g. if the target is 61, your score is 59 and you play a domino which scores 4, your score remains at 59). WHAT IS BEING ASSESSED In this assignment, we are not looking at who can write code to produce the best fives-and-threes dominos player. If you would like to try that challenge, you will have that opportunity at the end of semester, but that will not impact upon your mark for this module. What we are assessing here is: 1. The design of your solution, demonstrating that you have given some thought to the design of your player. It should be clear that you have given thought to the functional decomposition, and that you have experimented with the suggested strategies. (20%) 2. The testing of your solution, evidencing that you have tested your code thoroughly. You should not provide a random set of test data and output. You should give a rationale for the test cases that you have chosen. You may illustrate you testing with a carefully selected set of examples demonstrating that a function is working as intended, but make sure that it is clear to the reader why this set has been chosen. (30%) 3. The implementation of your solution, for both correctness and clarity. Your code should do what it is intended to do, but it should also be well-presented and understandable by others. This means sensible layout, code presented in a logical order, good choice of function and parameter names, consistency in style, clear comments (header documentation, function documentation, inline documentation where it is needed). (40%) 4. Your critical reflection about what you have learned when studying functional programming. (10%) More detail on each of these points is provided towards the end of this document. DOMSMATCH.HS You should take a copy of DomsMatch.hs from Blackboard and add your code to the bottom of this file. Note that near the top of this file there is the line "import System.Random”. System.Random is a library which is not installed by default, but it is essential in this project. You need to install it outside of ghci, at the command/terminal prompt, using the command: cabal install --lib random Once you have done this, start ghci, then type import System.Random COM2108: Functional Programming - Autumn 2023 3 at the Haskell prompt. If you don't get an error, you have successfully installed the library. This is the only library that you should install this way. If you try to use any other libraries that you have installed this way, your code will not run when it is submitted. This will result in a score of 0 for the implementation. DATATYPES The key datatypes are provided for you in the file DomsMatch.hs. You should not change these datatypes. These are: • Domino - representing a domino tile. • DominoBoard - which contains a current board state - - either the initial (that is, empty) board, or the current state, represented by: the left-most domino (with left-most pips in the first position in the tuple), the right-most domino (with right-most pips in the second position in the tuple), and the history of the game. • History - the layout of the board from left at the start of the list to right at the end of the list, where each domino is combined with which player played it and which turn at which it was played. • Player - essentially two labels to identify the individual players. • End indicating the end at which a tile is placed. • Scores - a tuple of scores representing (player 1's score, player 2's score) MoveNum to keep track of what was played when. • • Hand a set of dominos • DomsPlayer - this is the type of a function. A function of this type will return the move that it will make given the current Hand, Board, and Scores (Player is also an argument, indicating which player this player is, which may be useful if you wish to refer to the History when deciding on your move.) You can add extra datatypes if you wish. SCAFFOLDING FUNCTIONS A number of scaffolding functions are provided for you in DomsMatch.hs. The top-level function is domsMatch which as the name implies, plays a dominos match. It takes six arguments: the number of games to play in a match, the initial number of dominos in a hand, the target score, the two player functions, and a seed for the random number generator. Lower-level functions play a dominos game and a dominos round. Right now, these functions don't work properly, because they depend upon scoreBoard, blocked and playDom which are currently incorrectly implemented. The first thing you need to do is implement these functions. SCORING A BOARD The first function you must implement is scoreBoard. scoreBoard takes a Board and a Bool as arguments, where the Bool is True if the domino just played was the last domino from the hand, and False otherwise, and returns the score that would be received by creating this board state. For example, if the first player played (4,5), the board would contain just this domino, and so would score 3 (three threes - unless for some weird reason you were playing with an initial hand size of 1, in which case the score would be 2). If the next domino played was a (5,1) (which could only be played to the right end), the score on this board ([(4,5)(5,1)]) would be 1 (4+1 = 5; one five – again, unless you were playing with an initial hand size of 2...). COM2108: Functional Programming - Autumn 2023 4 Currently this function simply returns 0 for every input. CHECKING IF A PLAYER IS BLOCKED The next function to implement is blocked. blocked takes a Hand and a Board and is meant to return True only if there is no domino in the hand that can be played on the board. Currently this function always returns True. PLAYING A DOMINO Now you need to implement playDom, which given a Domino, a Board and an End, should play the domino at the given end if it is possible to play it there. The return type should be a Maybe Board. (See Errors and Uncertainty recording.) Currently this function always returns Nothing, but it should only return Nothing if it is not possible to play that domino at that end on the board. OTHER POSSIBLE BASIC FUNCTIONS Some other functions that might be useful include: • canPlay: a predicate (function that returns True or False) given a Domino, an End and a Board, returns True if the domino can be played at the given end the board. • played: a predicate returning True if a given Domino has already been played on a given Board. • • possPlays: given a Hand and a Board, return all the Dominos which may be played at the left End and all those that may be played at the right End. The return type should be a pair, where each item in the pair is a list of dominos. doms2scoreN: given a Board and an Int n, return all the Dominos not already played which could be played to give a fives-and-threes score of n and the End at which to play each one. You do not have to implement these functions; and before you even think about implementing them, you should complete your design and identify where (if anywhere) they will be used. You are certainly going to need to implement other functions than these as well. CREATING A SIMPLE PLAYER In DomsMatch.hs, you are provided with a data type for a DomsPlayer. This type is for a function that, given a particular Hand, Board, Player and Scores it returns a tuple (Domino, End) indicating the domino to be played and the end at which to play it. You must implement a function that will play a valid move when called. You should not attempt to implement any sophisticated reasoning at this stage. Your function must be called simplePlayer and it must be of type DomsPlayer. You do not have to check is it is possible to play a domino; you can assume that this function will only be called if the player has at least one domino in their hand that can be played on the current board. Remember, just one simple opponent is all that is needed at this stage. CREATING A "Smart” PlayER COM2108: Functional Programming - Autumn 2023 5See Answer

TutorBin Testimonials

I found TutorBin Haskell Programming homework help when I was struggling with complex concepts. Experts provided step-wise explanations and examples to help me understand concepts clearly.

Rick Jordon

5

TutorBin experts resolve your doubts without making you wait for long. Their experts are responsive & available 24/7 whenever you need Haskell Programming subject guidance.

Andrea Jacobs

5

I trust TutorBin for assisting me in completing Haskell Programming assignments with quality and 100% accuracy. Experts are polite, listen to my problems, and have extensive experience in their domain.

Lilian King

5

I got my Haskell Programming homework done on time. My assignment is proofread and edited by professionals. Got zero plagiarism as experts developed my assignment from scratch. Feel relieved and super excited.

Joey Dip

5

TutorBin helping students around the globe

TutorBin believes that distance should never be a barrier to learning. Over 500000+ orders and 100000+ happy customers explain TutorBin has become the name that keeps learning fun in the UK, USA, Canada, Australia, Singapore, and UAE.