Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. Re: failure $ cabal install wx (Jeffrey Brown)
2. Arithmetic expression parsing problem (m00nlight)
3. Re: Arithmetic expression parsing problem (Francesco Ariis)
4. Re: Arithmetic expression parsing problem (m00nlight)
5. Why does QuickCheck insist on this class constraint? (martin)
----------------------------------------------------------------------
Message: 1
Date: Sun, 29 Mar 2015 10:34:10 -0700
From: Jeffrey Brown <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] failure $ cabal install wx
Message-ID:
<CAEc4Ma1SdY=cqxuevettoy0dunjcaqdwqhv3nhe3bkv0ct6...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thank you, Brandon.
I tried installing a ton of wx libraries via zypper, and it didn't work.
Then I gave up and reverted to Kubuntu.
On Sat, Mar 28, 2015 at 6:38 PM, Brandon Allbery <[email protected]>
wrote:
> On Sat, Mar 28, 2015 at 9:34 PM, Jeffrey Brown <[email protected]>
> wrote:
>
>> gcc: error trying to exec 'cc1plus': execvp: No such file or directory
>>
>
> That part at least is because installing gcc on SuSE doesn't install the
> C++ compiler components. You'll need to find the package containing the C++
> components.
>
> --
> brandon s allbery kf8nh sine nomine
> associates
> [email protected]
> [email protected]
> unix, openafs, kerberos, infrastructure, xmonad
> http://sinenomine.net
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150329/509f7dad/attachment-0001.html>
------------------------------
Message: 2
Date: Mon, 30 Mar 2015 14:22:20 +0800 (CST)
From: m00nlight <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: [Haskell-beginners] Arithmetic expression parsing problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Dear Haskellers,
I am new to programming in haskell, recently I came up with an task to write an
simple arithemtic evaluator in
haskell. I try to write it using Text.Parsec, it can handle binary operation
and some unary operation, but will
give information of parsing error in some case. The following is my code
import Text.Parsec
import Text.Parsec.Expr
import Text.Parsec.Combinator
import Data.Functor
data Exp = Num Int
| Add Exp Exp
| Sub Exp Exp
| Mul Exp Exp
| Div Exp Exp
| Pos Exp
| Neg Exp
expr = buildExpressionParser table factor
table = [[op "*" (Mul) AssocRight, op "/" (Div) AssocRight]
,[op "+" (Add) AssocLeft, op "-" (Sub) AssocLeft]
,[prefix "-" (Neg), prefix "+" (Pos)]]
where op s f assoc = Infix (f <$ string s) assoc
prefix s f = Prefix (f <$ string s)
factor = between (char '(') (char ')') expr <|> (Num . read <$> many1 digit)
eval :: (Num a, Integral a) => Exp -> a
eval e = case e of
Num x -> fromIntegral x
Pos a -> eval a
Neg a -> negate $ eval a
Add a b -> eval a + eval b
Sub a b -> eval a - eval b
Mul a b -> eval a * eval b
Div a b -> eval a `div` eval b
solution :: (Num a, Integral a) => String -> a
solution = either (const (error "Did not parse")) eval . parse expr ""
The following is some test,
*Main> solution "-4/(2+3)"
0
*Main> solution "-4/(2-3)"
4
*Main> solution "-4/-2"
*** Exception: Did not parse
*Main> solution "16/-4"
*** Exception: Did not parse
*Main> solution "-16/4"
-4
*Main>
Can anyone teach me how to solve this? Thanks in advanced.
--m00nlight
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150330/35b8ed6c/attachment-0001.html>
------------------------------
Message: 3
Date: Mon, 30 Mar 2015 09:05:14 +0200
From: Francesco Ariis <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Arithmetic expression parsing problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Mon, Mar 30, 2015 at 02:22:20PM +0800, m00nlight wrote:
> I am new to programming in haskell, recently I came up with an task to
> write an simple arithemtic evaluator in haskell. I try to write it using
> Text.Parsec, it can handle binary operation and some unary operation,
> but will give information of parsing error in some case. The following
> is my code
>
> [..]
> Can anyone teach me how to solve this? Thanks in advanced.
Hello,
first things first, I slightly modified your `solution` function, so it
can fail with meaningful error messages
solution :: (Num a, Integral a) => String -> a
solution = either (error . show) eval . parse expr ""
Then I added to `<?>` operators at the end of your parsing expression
(again, for easier diagnostic).
factor = between (char '(') (char ')') expr
<|> (Num . read <$> many1 digit) <?> "factor"
expr = buildExpressionParser table factor <?> "expr"
Now the error message is:
?> solution "-4/-2"
*** Exception: (line 1, column 4):
unexpected "-"
expecting factor
So Parsec was expecting a "factor" element but found itself with '-'.
The first alternative of factor is not what we want (an expression
surrounded by parentheses).
The second part should be it (a 'number'). Now it is easy to recognise
the problem: `digit` only accepts digits and not '-' as a prefix.
When parsing stuff, <?>, small functions and early testing (with
hspec[1]) saved me much time and pain debugging.
[1] http://hspec.github.io/
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: Digital signature
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150330/3339da80/attachment-0001.sig>
------------------------------
Message: 4
Date: Mon, 30 Mar 2015 16:10:18 +0800 (CST)
From: m00nlight <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>
Subject: Re: [Haskell-beginners] Arithmetic expression parsing problem
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Hi Francesco,
Thanks for your explaination, so how can I modify the parser to handle this
case?
Can you give me some more details of how to modify it?
Thanks in advanced.
--m00nlight
?2015?03?30 15?05?, "Francesco Ariis"<[email protected]>??:
On Mon, Mar 30, 2015 at 02:22:20PM +0800, m00nlight wrote:
> I am new to programming in haskell, recently I came up with an task to
> write an simple arithemtic evaluator in haskell. I try to write it using
> Text.Parsec, it can handle binary operation and some unary operation,
> but will give information of parsing error in some case. The following
> is my code
>
> [..]
> Can anyone teach me how to solve this? Thanks in advanced.
Hello,
first things first, I slightly modified your `solution` function, so it
can fail with meaningful error messages
solution :: (Num a, Integral a) => String -> a
solution = either (error . show) eval . parse expr ""
Then I added to `<?>` operators at the end of your parsing expression
(again, for easier diagnostic).
factor = between (char '(') (char ')') expr
<|> (Num . read <$> many1 digit) <?> "factor"
expr = buildExpressionParser table factor <?> "expr"
Now the error message is:
?> solution "-4/-2"
*** Exception: (line 1, column 4):
unexpected "-"
expecting factor
So Parsec was expecting a "factor" element but found itself with '-'.
The first alternative of factor is not what we want (an expression
surrounded by parentheses).
The second part should be it (a 'number'). Now it is easy to recognise
the problem: `digit` only accepts digits and not '-' as a prefix.
When parsing stuff, <?>, small functions and early testing (with
hspec[1]) saved me much time and pain debugging.
[1] http://hspec.github.io/
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150330/d2b3f708/attachment-0001.html>
------------------------------
Message: 5
Date: Mon, 30 Mar 2015 13:22:44 +0200
From: martin <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] Why does QuickCheck insist on this class
constraint?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=utf-8
Hello all,
Ghc complainend about
Could not deduce (Arbitrary a1) arising from a use of ?arbitrary?
Could not deduce (Eq a1) arising from a use of ?arbitrary?
in the following code ..
data CList a = CList [Change a]
deriving Show
instance (Arbitrary c, Eq c) => Arbitrary (CList c)
where
arbitrary = do
ts <- orderedList :: Gen[Time]
vs <- listOf arbitrary :: Arbitrary c => Gen [c]
return $ CList $ zipWith (\t v -> Chg t v) (nub ts) vs
instance (Arbitrary a, Eq a) => Arbitrary (Temporal a)
where
arbitrary = do
d <- arbitrary
(CList cs) <- arbitrary :: (Arbitrary a, Eq a) => Gen (CList a)
-- <===
return (Temporal d cs)
..if I leave out the class constraints in the line maked with "<===". Why is
that so, i.e. why isn't the constraint four
lines up (in the instance declaration) sufficient?
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 81, Issue 73
*****************************************