stoyan.peev at gmail.com
Fri Jun 24 22:31:51 CEST 2011
I found the library myself, and i already put the code in that site:
That's what i have tried to do for making the task by calling the one
string function by another one:
parse :: [a] -> [a]
parse  = 
parse (x:xs) = eval (x:xs)
The error from the compiler:
ERROR file:.\list.hs:3 - Syntax error in declaration (unexpected `;',
possibly due to bad layout)
On Fri, Jun 24, 2011 at 11:20 PM, Daniel Patterson
<lists.haskell at dbp.mm.st> wrote:
> What have you tried to do in order to make it work for the list, and what error results? What is confusing about the error message? More generally, how could you transform an operation on a single string into one that does the same thing to a list of strings? You've probably talked about higher order functions in your class - would any of the common ones (filter, map, foldr) be helpful here? Would any encapsulate what you are trying to do?
> If you include these kinds of things, I think you'll find this community to be very helpful; without that (showing what your thought process is, why it isn't working, what seems confusing about what the haskell compiler is telling you, etc), you are not going to get help here. People here are very friendly and willing to help people learn; this is not a place to come to get an assignment finished :)
> Also, could you put the library you are using (I'm assuming that this is provided by your university) and the code on somewhere like hpaste.org, so that the formatting is not messed up by email, and it is syntax highlighted?
> On Jun 24, 2011, at 3:57 PM, Stoyan Peev wrote:
>> Hello all,
>> I am experiencing some issues to do my course task in university.
>> I have to write a calculator- function in Haskell. The function
>> argument is a list of strings and also form such list, as each string
>> of the argument made definite action:
>> - If the string has the form of an arithmetic _expression_ - calculate
>> this _expression_. The string result becomes part of the list-result.
>> If the _expression_ contains a variable which is not assigned value,
>> the result is displayed "undefined".
>> - If the string has the form- Name = value calculated from the last
>> _expression_ is assigned to the variable with the corresponding name
>> in the list, and in the result list is formed a string with type
>> - If there is not a calculated _expression_ to be assigned to form a
>> string "no value".
>> - If the string is non-blank, but there is a species different from
>> the above two case, form the string "error".
>> - If the string is empty, incl. when it contains only spaces, in the
>> result there is not form a string.
>> Expressions consist of integers without sign variables, operations +
>> (Addition), - (subtraction), * (multiplication) and / (divide) and
>> parentheses. Where no brackets, the operations are performed from left
>> to right, but * and / precede the + and -. Implementation of any
>> operation gives integer; in the division rejected the fractional part,
>> if any.
>> Variables have names of one letter - from the Latin small letter. In
>> the beginning, end or between the elements of each row can have spaces
>> - they are irrelevant to its correctness.
>> Example: the list-argument
>> ["3 +7 / 2" "2 + x", "= s", "2 * s +4", "", "2 + +4 / 5]
>> function should provide a result-list
>> ["6", "undefined", "s = 6", "16", "error"].
>> I say another person have the same task, but he didn't do anything. I
>> started doing this task myself but i get stuck in the middle. Then i
>> started searching for something that could help me and find out you :)
>> The code i have written so far uses the library file "Parsing.lhs"
>> but what i have written is taking those actions that i already
>> described, only for a string. I cannot modify it to work for list of
>> string, and complete the whole task.
>> I'll be glad to finish the task myself, but i am going to need some help.
>> Here is the code i have already written:
>> import Parsing
>> expr :: Parser Int
>> expr = do t <- term
>> do symbol "+"
>> e <- expr
>> return (t+e)
>> +++ do symbol "-"
>> e <- expr
>> return (t-e)
>> +++ return t
>> term :: Parser Int
>> term = do f <- factor
>> do symbol "*"
>> t <- term
>> return (f * t)
>> +++ do symbol "/"
>> t <- term
>> return (f-t)
>> +++ return f
>> factor :: Parser Int
>> factor = do symbol "("
>> e <- expr
>> symbol ")"
>> return e
>> +++ natural
>> eval :: String -> Int
>> eval xs = case (parse expr xs) of
>> [(n,)] -> n
>> [(_,out)] -> error ("undefined")
>>  -> error "error"
>> Thanks all in advance :)
>> Best Wishes
>> Stoyan Peev
>> Haskell-Cafe mailing list
>> Haskell-Cafe at haskell.org
More information about the Haskell-Cafe