martin | 31 Mar 07:33 2015
Picon

Are Arrows good for simulation purposes

Hello all,

little do I know about arrows, but the "stream processor" metaphor suggests, that they can be used to
simulate a network
of things, services or data. Is this correct?

I came across the following thought: When I simulate a billard game with a DES, I would compute collisions of
balls with
each other and with the banks, creatign a set of events, of which only the earliest will be considered to
compute the
next state. This is pure DES and does not seem to be a good candidate for arrows. In this case I'd be more
interested in
composing collision detectors than in stream processing.

OTOH, when I move parcels around and process then in various stages, then a "stream processor" would make
perfect sense
to me. In that case, would I abandon the DES paradigm entirely (including the notion of an event queue) and
just model
the network and let it run?

Thomas Koster | 31 Mar 05:26 2015
Picon

Is there an aeson-like XML serialization library?

Hi list,

I want to write a simple XML web service in Haskell that services a .NET WCF client, but am struggling with choosing the right XML library.

"aeson" [1] has been a pleasure to use, so I am looking for an XML serialization library similar to aeson, where I can write ToElement/FromElement instances using simple applicative combinators, working with a high-level document model (i.e. not a parse tree), just like I have done in the past with ToJSON/FromJSON.

Does such a library exist?

I need the library to understand XML namespaces and the mandatory predefined entities, but I do not need any other extensions like XML Schemas, XPath or XSLT. Preferably, "xmlns" attributes should be handled specially and namespace prefixes resolved by the parser. "xmlns" attributes should be placed automatically by the renderer (I don't care what prefixes it chooses). I do not want to have to keep track of seen namespace prefixes while I am traversing the document, or to manually place "xmlns" attributes on elements for rendering. The "xml" [2] library is giving me grief at the moment with how unspecial its treatment of namespaces is.

HXT appears to be beyond my skill level at the moment. There appear to be too many new things I would have to learn all at once before I could use it for this simple task. Cf. aeson, which I was able to use for practical applications the day I learned what an applicative functor was.


Thanks,
--
Thomas Koster

<div><div dir="ltr">Hi list,<div><br></div>
<div>I want to write a simple XML web service in Haskell that services a .NET WCF client, but am struggling with choosing the right XML library.</div>
<div><br></div>
<div>"aeson" [1] has been a pleasure to use, so I am looking for an XML serialization library similar to aeson, where I can write ToElement/FromElement instances using simple applicative combinators, working with a high-level document model (i.e. not a parse tree), just like I have done in the past with ToJSON/FromJSON.<br>
</div>
<div><br></div>
<div>
<div><div>Does such a library exist?<br>
</div></div>
<div><br></div>
<div>I need the library to understand XML namespaces and the mandatory predefined entities, but I do not need any other extensions like XML Schemas, XPath or XSLT. Preferably, "xmlns" attributes should be handled specially and namespace prefixes resolved by the parser. "xmlns" attributes should be placed automatically by the renderer (I don't care what prefixes it chooses). I do not want to have to keep track of seen namespace prefixes while I am traversing the document, or to manually place "xmlns" attributes on elements for rendering. The "xml" [2] library is giving me grief at the moment with how unspecial its treatment of namespaces is.</div>
</div>
<div><br></div>
<div>HXT appears to be beyond my skill level at the moment. There appear to be too many new things I would have to learn all at once before I could use it for this simple task. Cf. aeson, which I was able to use for practical applications the day I learned what an applicative functor was.<br>
</div>
<div><br></div>
<div>[1]&nbsp;<a href="https://hackage.haskell.org/package/aeson">https://hackage.haskell.org/package/aeson</a>
</div>
<div>[2] <a href="https://hackage.haskell.org/package/xml">https://hackage.haskell.org/package/xml</a><br>
</div>
<div><br></div>
<div>Thanks,</div>
<div>--</div>
<div>Thomas Koster</div>
<div><br></div>
</div></div>
Jeffrey Brown | 31 Mar 04:14 2015
Picon

Mutable collection of gui objects (wxHaskell)

Hi,

On Github, Jeremy O'Donoghue provides wx example code. From his collection I am trying to modify Layout.hs [1] to permit a variable number, rather than a fixed number, of text entry boxes. I shrank the program, mostly by removing features, until it was this:

  main = start $ do
    f      <- frame  [text := "Layout test"]
    p      <- panel  f []
    xinput <- textEntry p [text := "100"]
    yinput <- textEntry p [text := "100"]
    myVar <- varCreate [xinput,yinput]
    set f [ layout := container p $ margin 10 $
      column 5 [boxed "coordinates" (grid 5 5
          [[hfill $ widget xinput], [hfill $ widget yinput]] -- replacing
        ) ] ]                                         
    return ()

I want to replace the line marked "replacing". Rather than hard-coding the number of text entry boxes (2), I want it to deal with a mutable collection of them, in myVar.

I tried this:
  [ fmap (\e -> hfill $ widget e) $ varGet myVar ]
and got this error:
  Layout.hs:23:11:
      Couldn't match type `IO' with `[]'
      Expected type: [Layout]
        Actual type: IO Layout
      In the expression: fmap (\ e -> hfill $ widget e) $ varGet myVar
      In the third argument of `grid', namely
        `[fmap (\ e -> hfill $ widget e) $ varGet myVar]'
      In the second argument of `boxed', namely
        `(grid 5 5 [fmap (\ e -> hfill $ widget e) $ varGet myVar])'

So then I tried something I thought would be equivalent:
  [[ (hfill $ widget e) | e <- (varGet myVar)]]
and got a different error:
  Layout.hs:23:39:
      Couldn't match expected type `[w0]'
                  with actual type `IO [TextCtrl ()]'
      In the return type of a call of `varGet'
      In the expression: (varGet myVar)
      In a stmt of a list comprehension: e <- (varGet myVar)

I kind of understand the problem is that when I varGet myVar, I end up with type IO Layout, rather than type Layout, but I don't know what to do about it.

Thanks,
Jeff


[1] https://github.com/jodonoghue/wxHaskell/blob/master/samples/wx/Layout.hs
<div><div dir="ltr">Hi,<br><br>On Github, Jeremy O'Donoghue provides wx example code. From his collection I am trying to modify Layout.hs [1] to permit a variable number, rather than a fixed number, of text entry boxes. I shrank the program, mostly by removing features, until it was this:<br><br>&nbsp; main = start $ do<br>&nbsp;&nbsp;&nbsp; f&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;- frame&nbsp; [text := "Layout test"]<br>&nbsp;&nbsp;&nbsp; p&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &lt;- panel&nbsp; f []<br>&nbsp;&nbsp;&nbsp; xinput &lt;- textEntry p [text := "100"]<br>&nbsp;&nbsp;&nbsp; yinput &lt;- textEntry p [text := "100"]<br>&nbsp;&nbsp;&nbsp; myVar &lt;- varCreate [xinput,yinput]<br>&nbsp;&nbsp;&nbsp; set f [ layout := container p $ margin 10 $<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; column 5 [boxed "coordinates" (grid 5 5<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; [[hfill $ widget xinput], [hfill $ widget yinput]] -- replacing<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ) ] ]&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; return ()<br><br>I want to replace the line marked "replacing". Rather than hard-coding the number of text entry boxes (2), I want it to deal with a mutable collection of them, in myVar.<br><br>I tried this:<br>&nbsp; [ fmap (\e -&gt; hfill $ widget e) $ varGet myVar ]<br>and got this error: <br>&nbsp; Layout.hs:23:11:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Couldn't match type `IO' with `[]'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Expected type: [Layout]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Actual type: IO Layout<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the expression: fmap (\ e -&gt; hfill $ widget e) $ varGet myVar<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the third argument of `grid', namely<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `[fmap (\ e -&gt; hfill $ widget e) $ varGet myVar]'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the second argument of `boxed', namely<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; `(grid 5 5 [fmap (\ e -&gt; hfill $ widget e) $ varGet myVar])'<br><br>So then I tried something I thought would be equivalent:<br>&nbsp; [[ (hfill $ widget e) | e &lt;- (varGet myVar)]]<br>and got a different error:<br>&nbsp; Layout.hs:23:39:<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Couldn't match expected type `[w0]'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; with actual type `IO [TextCtrl ()]'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the return type of a call of `varGet'<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In the expression: (varGet myVar)<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; In a stmt of a list comprehension: e &lt;- (varGet myVar)<br><br>I kind of understand the problem is that when I varGet myVar, I end up with type IO Layout, rather than type Layout, but I don't know what to do about it.<br><br>Thanks,<br>Jeff<br><br><br>[1] <a href="https://github.com/jodonoghue/wxHaskell/blob/master/samples/wx/Layout.hs">https://github.com/jodonoghue/wxHaskell/blob/master/samples/wx/Layout.hs</a><br>
</div></div>
martin | 30 Mar 13:22 2015
Picon

Why does QuickCheck insist on this class constraint?

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?
_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
m00nlight | 30 Mar 08:22 2015
Picon

Arithmetic expression parsing problem

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



<div>
<div>
<div>Dear Haskellers,<br><br>I am new to programming in haskell, recently I came up with an task to write an simple arithemtic evaluator in <br>haskell. I try to write it using Text.Parsec, it can handle binary operation and some unary operation, but will <br>give information of parsing error in some case. The following is my code<br><br><br>
</div>
<div>import Text.Parsec<br>import Text.Parsec.Expr<br>import Text.Parsec.Combinator<br>import Data.Functor<br><br>data Exp = Num Int<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Add Exp Exp<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Sub Exp Exp<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Mul Exp Exp<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Div Exp Exp<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Pos Exp<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; | Neg Exp<br><br>expr = buildExpressionParser table factor<br><br><br>table = [[op "*" (Mul) AssocRight, op "/" (Div) AssocRight]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,[op "+" (Add) AssocLeft, op "-" (Sub) AssocLeft]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ,[prefix "-" (Neg), prefix "+" (Pos)]]<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; where op s f assoc = Infix (f &lt;$ string s) assoc<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; prefix s f = Prefix (f &lt;$ string s)<br><br><br>factor = between (char '(') (char ')') expr &lt;|&gt; (Num . read &lt;$&gt; many1 digit)<br><br>eval :: (Num a, Integral a) =&gt; Exp -&gt; a<br>eval e = case e of<br>&nbsp;&nbsp;&nbsp; Num x&nbsp;&nbsp; -&gt; fromIntegral x<br>&nbsp;&nbsp;&nbsp; Pos a&nbsp;&nbsp; -&gt; eval a<br>&nbsp;&nbsp;&nbsp; Neg a&nbsp;&nbsp; -&gt; negate $ eval a<br>&nbsp;&nbsp;&nbsp; Add a b -&gt; eval a&nbsp;&nbsp; +&nbsp;&nbsp; eval b<br>&nbsp;&nbsp;&nbsp; Sub a b -&gt; eval a&nbsp;&nbsp; -&nbsp;&nbsp; eval b<br>&nbsp;&nbsp;&nbsp; Mul a b -&gt; eval a&nbsp;&nbsp; *&nbsp;&nbsp; eval b<br>&nbsp;&nbsp;&nbsp; Div a b -&gt; eval a `div` eval b<br><br>solution :: (Num a, Integral a) =&gt; String -&gt; a<br>solution = either (const (error "Did not parse")) eval . parse expr ""<br><br>The following is some test,<br><br><br>
</div>
<div>*Main&gt; solution "-4/(2+3)"<br>0<br>*Main&gt; solution "-4/(2-3)"<br>4<br>*Main&gt; solution "-4/-2"<br>*** Exception: Did not parse<br>*Main&gt; solution "16/-4"<br>*** Exception: Did not parse<br>*Main&gt; solution "-16/4"<br>-4<br>*Main&gt;<br><br>Can anyone teach me how to solve this?&nbsp; Thanks in advanced.<br><br><br><br>
</div>
</div>
<div name="100"><div><div>--m00nlight<br>
</div></div></div>
<div><br></div>
<br><br><span title="neteasefooter"><span><span title="neteasefooter"><span><a href="#" target="_blank"></a></span></span>
</span></span>
</div>
Jeffrey Brown | 29 Mar 03:34 2015
Picon

failure $ cabal install wx

Hi!

I first sent this to Haskell-Cafe, then thought this would be a better destination.

I switched OSs, from Ubuntu to OpenSuse 13.2, to fix some other problems. I since installed The Haskell Platform, and would like to install wxHaskell.

The first time I tried that under OpenSuse, cabal install wx provided more output, installing a lot of things. Since then it has only given this:

    jeff <at> linux-ee07:~> cabal install wx
    Resolving dependencies...
    [1 of 1] Compiling Main             ( /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/Setup.hs, /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/dist/setup/Main.o )
    Linking /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/dist/setup/setup ...
    Configuring wxc-0.91.0.0...
   
                        Warning: No config found to match: /usr/bin/wx-config --version=2.9 --version-full
                                         in /usr/lib64/wx/config
                        If you require this configuration, please install the desired
                        library build.  If this is part of an automated configuration
                        test and no other errors occur, you may safely ignore it.
                        You may use wx-config --list to see all configs available in
                        the default prefix.
   
    readProcess failed: readProcess: wx-config "--version=2.9" "--version-full" (exit 1): failed
    Configuring wxc to build against wxWidgets 3.0.2.0
   
    Building wxc
    /usr/bin/gcc -Wl,--hash-size=31 -Wl,--reduce-memory-overheads -Wl,--disable-new-dtags -Isrc/include -I/usr/include/wx-3.0 -I/usr/lib64/wx/include/gtk3-unicode-3.0 -D__WXGTK__ -DWXUSINGDLL -DwxDEBUG_LEVEL=0 -D_FILE_OFFSET_BITS=64 -DwxcREFUSE_MEDIACTRL -fPIC -c src/cpp/apppath.cpp -o dist/build/src/cpp/apppath.o
    gcc: error trying to exec 'cc1plus': execvp: No such file or directory
    Failed to install wxc-0.91.0.0
    cabal: Error: some packages failed to install:
    wx-0.91.0.0 depends on wxc-0.91.0.0 which failed to install.
    wxc-0.91.0.0 failed during the building phase. The exception was:
    ExitFailure 1
    wxcore-0.91.0.0 depends on wxc-0.91.0.0 which failed to install.
    jeff <at> linux-ee07:~>

The file /usr/bin/wx-config exists. It may have gotten there today when I installed some wx packages via zypper (OpenSuse's equivalent to apt-get). I don't remember which those packages were, but in the wx-configg file appear these lines:

    this_version="3.0"
    [ -z "$output_option_release"       ] || echo "3.0"
    [ -z "$output_option_version"       ] || echo "3.0.2"
    [ -z "$output_option_version_full"  ] || echo "3.0.2.0"

so I believe the version of wx I have is 3.0.2.0.

I'm using a Lenovo Thinkpad Edge 535 or 545.

Thanks,
Jeff
<div><div dir="ltr">
<div>Hi!<br><br>I first sent this to Haskell-Cafe, then thought this would be a better destination.<br><br>
</div>I switched OSs, from Ubuntu to OpenSuse 13.2, to fix some other problems. I since installed The Haskell Platform, and would like to install wxHaskell.<br><br>The
 first time I tried that under OpenSuse, cabal install wx provided more output, installing a lot of things. Since then it has only given 
this:<br><br>&nbsp;&nbsp;&nbsp; jeff <at> linux-ee07:~&gt; cabal install wx<br>&nbsp;&nbsp;&nbsp; Resolving dependencies...<br>&nbsp;&nbsp;&nbsp; [1 of 1] Compiling Main&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ( /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/Setup.hs, /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/dist/setup/Main.o )<br>&nbsp;&nbsp;&nbsp; Linking /tmp/wxc-0.91.0.0-16672/wxc-0.91.0.0/dist/setup/setup ...<br>&nbsp;&nbsp;&nbsp; Configuring wxc-0.91.0.0...<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; Warning: No config found to match: /usr/bin/wx-config --version=2.9 --version-full<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;in /usr/lib64/wx/config<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; If you require this configuration, please install the desired<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; library build.&nbsp; If this is part of an automated configuration<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; test and no other errors occur, you may safely ignore it.<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; You may use wx-config --list to see all configs available in<br>&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; &nbsp;&nbsp;&nbsp; the default prefix.<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; readProcess failed: readProcess: wx-config "--version=2.9" "--version-full" (exit 1): failed<br>&nbsp;&nbsp;&nbsp; Configuring wxc to build against wxWidgets 3.0.2.0<br>&nbsp;&nbsp;&nbsp; <br>&nbsp;&nbsp;&nbsp; Building wxc<br>&nbsp;&nbsp;&nbsp;
 /usr/bin/gcc -Wl,--hash-size=31 -Wl,--reduce-memory-overheads 
-Wl,--disable-new-dtags -Isrc/include -I/usr/include/wx-3.0 
-I/usr/lib64/wx/include/gtk3-unicode-3.0 -D__WXGTK__ -DWXUSINGDLL 
-DwxDEBUG_LEVEL=0 -D_FILE_OFFSET_BITS=64 -DwxcREFUSE_MEDIACTRL -fPIC -c 
src/cpp/apppath.cpp -o dist/build/src/cpp/apppath.o<br>&nbsp;&nbsp;&nbsp; gcc: error trying to exec 'cc1plus': execvp: No such file or directory<br>&nbsp;&nbsp;&nbsp; Failed to install wxc-0.91.0.0<br>&nbsp;&nbsp;&nbsp; cabal: Error: some packages failed to install:<br>&nbsp;&nbsp;&nbsp; wx-0.91.0.0 depends on wxc-0.91.0.0 which failed to install.<br>&nbsp;&nbsp;&nbsp; wxc-0.91.0.0 failed during the building phase. The exception was:<br>&nbsp;&nbsp;&nbsp; ExitFailure 1<br>&nbsp;&nbsp;&nbsp; wxcore-0.91.0.0 depends on wxc-0.91.0.0 which failed to install.<br>&nbsp;&nbsp;&nbsp; jeff <at> linux-ee07:~&gt; <br><br>The
 file /usr/bin/wx-config exists. It may have gotten there today when I 
installed some wx packages via zypper (OpenSuse's equivalent to apt-get). I don't 
remember which those packages were, but in the wx-configg file appear these lines:<br><br>&nbsp;&nbsp;&nbsp; this_version="3.0" <br>&nbsp;&nbsp;&nbsp; [ -z "$output_option_release"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ] || echo "3.0"<br>&nbsp;&nbsp;&nbsp; [ -z "$output_option_version"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ] || echo "3.0.2"<br>&nbsp;&nbsp;&nbsp; [ -z "$output_option_version_full"&nbsp; ] || echo "3.0.2.0"<br><br>so I believe the version of wx I have is 3.0.2.0.<br><br>I'm using a Lenovo Thinkpad Edge 535 or 545.<br><br>Thanks,<br>Jeff</div></div>
Animesh Saxena | 28 Mar 05:10 2015

Automatic Differentiation

I was implementing automatic differentiation in haskell and was able to code the calculation part, but I
wanted to extend it to show the symbols instead of just the final value.
Let me explain and copy/paste the code…

3  data ADif a = ADif a a deriving (Eq)

10 instance Floating x => Floating (ADif x) where
11           pi = ADif pi 0
12           exp    (ADif x x') = ADif (exp    x) (x' * exp x)
13           log    (ADif x x') = ADif (log    x) (x' / x)
14           sqrt   (ADif x x') = ADif (sqrt   x) (x' / (2 * sqrt x))
15           sin    (ADif x x') = ADif (sin    x) (x' * cos x)
16           cos    (ADif x x') = ADif (cos    x) (x' * (- sin x))
….And so on all the functions

27 instance Num x => Num (ADif x) where
28         ADif x x' + ADif y y' = ADif (x+y) (x'+y')
29         ADif x x' * ADif y y' = ADif (x*y) (y'*x + x'*y)
30         fromInteger x = fromInteger x

let myfunction x = exp (log (sin x))
*Main> myfunction (ADif 2 1)
-0.4161468365471424

I verified that this is the correct solution by hand! (& well mathematica too!)

Anyway now I was hoping to print the actual symbols, so I was googling around for extending “Show”
typeclass for floating and Num, kinda similar pattern. Is this the right approach? Or I need to rethink the problem?
Basically my aim is to do something like mathematica where if I specify D[f[x],x] then I get the answer in
symbols. 

-Animesh
_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Maurizio Vitale | 27 Mar 14:38 2015
Picon

parser frontend

G'day,
  I'm trying to decide how to architect the frontend of a compiler I'm using as an excuse for learning Haskell.

  Suppose we have a language (SystemVerilog) that has the notion of multi-file compilation units.
This means that specific subset of files form separate scopes for certain things.
For instance if we represent with lists of lists compilation units:
[[a,b,c], [d], [e,f]]
a macro definition in file b, would affect the rest of the file and file c, but wouldn't have effect on files d,e or a.

Furthermore, if a toplevel construct is split between two files, say c and d, the compiler should treat the original compilation unit specification as if it was:
[[a,b,(c,d)][e,f]], where (c,d) means we're compiling the logical concatenation of c and d.
If (c,d) is also incomplete, (c,d,e) should be tried and so on.

Now in well designed systems, all files can actually be compiled in parallel and so I'd like to optimize for that case and recompile files (either because we need side effects from files before them or because they're incomplete. So I'm not to concerned if wasted work is done for the degenerate cases.

Any suggestion on how to go about this?
Le's assume that parsing a file is done with a function:
p :: file -> Either Error (ast, [defs], [use]) where the [defs] are things that might affects files down the line and [use] are things that, if defined by some prior file, cause recompilation.

I'm interested in both a sequential and parallel solution and it would be sweet if they where similar, with the proper abstractions.

Thanks a lot for any insight/ideas,

  Maurizio
<div><div dir="ltr">G'day,<div>&nbsp; I'm trying to decide how to architect the frontend of a compiler I'm using as an excuse for learning Haskell.</div>
<div>
<br><div>&nbsp; Suppose we have a language (SystemVerilog) that has the notion of multi-file compilation units.</div>
<div>This means that specific subset of files form separate scopes for certain things.</div>
<div>For instance if we represent with lists of lists compilation units:</div>
<div>[[a,b,c], [d], [e,f]]</div>
<div>a macro definition in file b, would affect the rest of the file and file c, but wouldn't have effect on files d,e or a.</div>
<div><br></div>
<div>Furthermore, if a toplevel construct is split between two files, say c and d, the compiler should treat the original compilation unit specification as if it was:</div>
<div>[[a,b,(c,d)][e,f]], where (c,d) means we're compiling the logical concatenation of c and d.</div>
<div>If (c,d) is also incomplete, (c,d,e) should be tried and so on.</div>
<div><br></div>
<div>Now in well designed systems, all files can actually be compiled in parallel and so I'd like to optimize for that case and recompile files (either because we need side effects from files before them or because they're incomplete. So I'm not to concerned if wasted work is done for the degenerate cases.</div>
</div>
<div><br></div>
<div>Any suggestion on how to go about this?</div>
<div>Le's assume that parsing a file is done with a function:</div>
<div>p :: file -&gt; Either Error (ast, [defs], [use]) where the [defs] are things that might affects files down the line and [use] are things that, if defined by some prior file, cause recompilation.<br>
</div>
<div><br></div>
<div>I'm interested in both a sequential and parallel solution and it would be sweet if they where similar, with the proper abstractions.</div>
<div><br></div>
<div>Thanks a lot for any insight/ideas,</div>
<div><br></div>
<div>&nbsp; Maurizio</div>
</div></div>
Norbert Melzer | 27 Mar 13:31 2015
Picon

Writing a Parser with attoparsec that reads from a list of tokens

Hi there!

I want to write some small toy language using attoparsec.

So I thought, first step tokenize. Let attoparsec consume the input stream and produce a list of tokens.
Second step, parse tokens and produce the AST.

Using parsec this would be possible easily and is documented. But I want to use attoparsec for this task, because I am interested in attoparsecs capability to have the input in chunks.

TIA
Norbert
<div><div dir="ltr">Hi there!<div><br></div>
<div>I want to write some small toy language using attoparsec.</div>
<div><br></div>
<div>So I thought, first step tokenize. Let attoparsec consume the input stream and produce a list of tokens.</div>
<div>Second step, parse tokens and produce the AST.</div>
<div><br></div>
<div>Using parsec this would be possible easily and is documented. But I want to use attoparsec for this task, because I am interested in attoparsecs capability to have the input in chunks.</div>
<div><br></div>
<div>TIA</div>
<div>Norbert</div>
</div></div>
martin | 26 Mar 21:18 2015
Picon

ap = liftM2 id

Hello all,

can someone explain

ap  =  liftM2 id

to me? liftM2 wants a binary funcation

liftM2  :: (Monad m) => (a1 -> a2 -> r) -> m a1 -> m a2 -> m r

but id is unary. How does this work?
Corentin Dupont | 26 Mar 18:31 2015
Picon

Re: Maybe and Just

Not really, when you define the type "Maybe a":

data Maybe a = Just a | Nothing

Haskell is creating automatically two functions for you:

Just :: a -> Maybe a
Nothing :: Maybe a

In the first case, you can think of "Just" and "Nothing" as a sort of tag identifying which element of the sum you have.
It the second case it's a function, with the same name.
A more informed person than me could say if they are indeed separated of if they are the same thing in GHC...


On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava <shishir.srivastava <at> gmail.com> wrote:
isn't that then cyclic dependency between 'Maybe' and 'Just' ...where the first one is defined in terms of second and vice-versa...?

Shishir 


On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont <corentin.dupont <at> gmail.com> wrote:
Hi Shishir,
I think that's a legitimate question.

By writing

data Maybe a = a | Nothing

you are saying that the type of the left hand side of the = is the same that right hand side (you are defining a type basically).
Also you can only sum things of the same type.
So you are saying:
type "Maybe a" = type "a"
Which is wrong.
That's why "a" should be wrapped into something:
type of "Just a" is indeed "Maybe a".

"Just" is a type constructor:
Just :: a -> Maybe a
It allows you to build the Maybe.

Said that, "Just" is a vocabulary choice.
Personally I prefer the name choices of OCaml, Rust, Scala etc.: Option a = None | Some a



On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava <shishir.srivastava <at> gmail.com> wrote:
ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be defined like this 

data Maybe a = a | Nothing

what's the point in having 'Just' keyword ?

Shishir


On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman <mdorman <at> ironicdesign.com> wrote:
Shishir Srivastava <shishir.srivastava <at> gmail.com> writes:
> After reading and re-reading the haskell tutorials I don't happen to
> see a very convincing or appealing reason for having these data
> types.

To be clear: Maybe is the data *type*.  Just and Nothing are its data
*constructors*.

> Can anyone please explain where Maybe and Just provide the sort of
> functionality that cannot be achieved in other languages which don't
> have these kind.

The functionality can be achieved in other languages, certainly.  The
question is whether the clarity and safety is also achieved.

When I see (as a totally contrived example):

  fopen :: Maybe FileHandle

I know that that function may not be able to return a FileHandle value
all the time.  The compiler will, in fact, nag me if I do not write the
code that calls it in such a way that it acknowledges that possibility.

When I see:

  FILE * fopen ( const char * filename, const char * mode );

It is not immediately clear whether that can fail.  Sure, we can make
that inference, based on what we know about filesystems, etc., but the
compiler is never going to complain if I ignore the possibility.

In my experience, programmers in many languages end up resorting to
convention to try and work around these sorts of ambiguities.  Large
projects have strategies for naming functions that try to pass along
information out of band, or languages have a pervasive culture of "lint"
tools that try to use heuristics to make up for what the type system
doesn't make simple.

That said, I know that doing Maybe sorts of things in languages that
don't have, say, pattern matching, or the idea of a "failure monad",
gets to be a drag very quickly---manually unwrapping things is at best
awkward, having to re-wrap them just to unwrap them again in a sequence
of computations quickly leads one to believe "it's just not worth
it"---or you resort to exception handling, which has its own challenges
to do well.

Mike.


_______________________________________________
Beginners mailing list
Beginners <at> haskell.org
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners




<div><div dir="ltr">
<div>
<div>Not really, when you define the type "Maybe a":<br><br><span><span>data Maybe a = Just a | Nothing<br><br></span></span>
</div>
<span><span>Haskell is creating automatically two functions for you:<br><br></span></span><span>Just :: a -&gt; Maybe a<br></span>
</div>
<span>Nothing :: Maybe a<br></span><div><div>
<span><span><br></span></span><div>
<div class="gmail_extra">In the first case, you can think of "Just" and "Nothing" as a sort of tag identifying which element of the sum you have.<br>
</div>
<div class="gmail_extra">It the second case it's a function, with the same name.<br>
</div>
<div class="gmail_extra">A more informed person than me could say if they are indeed separated of if they are the same thing in GHC...<br>
</div>
<div class="gmail_extra">
<br><br><div class="gmail_quote">On Thu, Mar 26, 2015 at 5:34 PM, Shishir Srivastava <span dir="ltr">&lt;<a href="mailto:shishir.srivastava <at> gmail.com" target="_blank">shishir.srivastava <at> gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">
<div dir="ltr">isn't that then cyclic dependency between 'Maybe' and 'Just' ...where the first one is defined in terms of second and vice-versa...?<div class="gmail_extra">
<span class=""><br clear="all"><div><div><div dir="ltr">Shishir&nbsp;<br><br>
</div></div></div></span><div><div class="h5">
<br><div class="gmail_quote">On Thu, Mar 26, 2015 at 3:48 PM, Corentin Dupont <span dir="ltr">&lt;<a href="mailto:corentin.dupont <at> gmail.com" target="_blank">corentin.dupont <at> gmail.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">
<div dir="ltr">
<div>
<div>
<div>
<div>
<div>
<div>Hi Shishir,<br>
</div>I think that's a legitimate question.<br><br>
</div>By writing <br><span><br><span>data Maybe a = a | Nothing</span><br><br></span>
</div>you are saying that the type of the left hand side of the = is the same that right hand side (you are defining a type basically).<br>
</div>
<div>Also you can only sum things of the same type.<br>
</div>So you are saying:<br>
</div>
<span>type "Maybe a" = type "a"</span><br>
</div>Which is wrong.<br><div>
<div>That's why "a" should be wrapped into something:<br>
</div>
<div>type of "Just a" is indeed "Maybe a".<br><br>
</div>
<div>"Just" is a type constructor:<br><span>Just :: a -&gt; Maybe a</span><br>
</div>
<div>It allows you to build the Maybe.<br><br>
</div>
<div>Said that, "Just" is a vocabulary choice. <br>Personally I prefer the name choices of OCaml, Rust, Scala etc.: Option a = None | Some a<br>
</div>
<div><br></div>
<div><div><div><br></div></div></div>
</div>
</div>
<div class="gmail_extra">
<br><div class="gmail_quote">
<div><div>On Thu, Mar 26, 2015 at 4:26 PM, Shishir Srivastava <span dir="ltr">&lt;<a href="mailto:shishir.srivastava <at> gmail.com" target="_blank">shishir.srivastava <at> gmail.com</a>&gt;</span> wrote:<br>
</div></div>
<blockquote class="gmail_quote">
<div><div>
<div dir="ltr">
<span>ok..but what's with using the keyword 'Just' ? why cannot 'Maybe' be defined like this&nbsp;</span><div><br></div>
<div>data Maybe a = a | Nothing<br>
</div>
<div><br></div>
<div>what's the point in having 'Just' keyword ?</div>
<div class="gmail_extra">
<span><br clear="all"><div><div><div dir="ltr">Shishir<br><br>
</div></div></div></span><div><div>
<br><div class="gmail_quote">On Thu, Mar 26, 2015 at 10:26 AM, Michael Alan Dorman <span dir="ltr">&lt;<a href="mailto:mdorman <at> ironicdesign.com" target="_blank">mdorman <at> ironicdesign.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote">
<span>Shishir Srivastava &lt;<a href="mailto:shishir.srivastava <at> gmail.com" target="_blank">shishir.srivastava <at> gmail.com</a>&gt; writes:<br>
&gt; After reading and re-reading the haskell tutorials I don't happen to<br>
&gt; see a very convincing or appealing reason for having these data<br>
&gt; types.<br><br></span>To be clear: Maybe is the data *type*.&nbsp; Just and Nothing are its data<br>
*constructors*.<br><span><br>
&gt; Can anyone please explain where Maybe and Just provide the sort of<br>
&gt; functionality that cannot be achieved in other languages which don't<br>
&gt; have these kind.<br><br></span>The functionality can be achieved in other languages, certainly.&nbsp; The<br>
question is whether the clarity and safety is also achieved.<br><br>
When I see (as a totally contrived example):<br><br>
&nbsp; fopen :: Maybe FileHandle<br><br>
I know that that function may not be able to return a FileHandle value<br>
all the time.&nbsp; The compiler will, in fact, nag me if I do not write the<br>
code that calls it in such a way that it acknowledges that possibility.<br><br>
When I see:<br><br>
&nbsp; FILE * fopen ( const char * filename, const char * mode );<br><br>
It is not immediately clear whether that can fail.&nbsp; Sure, we can make<br>
that inference, based on what we know about filesystems, etc., but the<br>
compiler is never going to complain if I ignore the possibility.<br><br>
In my experience, programmers in many languages end up resorting to<br>
convention to try and work around these sorts of ambiguities.&nbsp; Large<br>
projects have strategies for naming functions that try to pass along<br>
information out of band, or languages have a pervasive culture of "lint"<br>
tools that try to use heuristics to make up for what the type system<br>
doesn't make simple.<br><br>
That said, I know that doing Maybe sorts of things in languages that<br>
don't have, say, pattern matching, or the idea of a "failure monad",<br>
gets to be a drag very quickly---manually unwrapping things is at best<br>
awkward, having to re-wrap them just to unwrap them again in a sequence<br>
of computations quickly leads one to believe "it's just not worth<br>
it"---or you resort to exception handling, which has its own challenges<br>
to do well.<br><br>
Mike.<br>
</blockquote>
</div>
<br>
</div></div>
</div>
</div>
<br>
</div></div>_______________________________________________<br>
Beginners mailing list<br><a href="mailto:Beginners <at> haskell.org" target="_blank">Beginners <at> haskell.org</a><br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners" target="_blank">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br><br>
</blockquote>
</div>
<br>
</div>
</blockquote>
</div>
<br>
</div></div>
</div>
</div>
</blockquote>
</div>
<br>
</div>
</div>
</div></div>
</div></div>

Gmane