Send Beginners mailing list submissions to
        [email protected]

To subscribe or unsubscribe via the World Wide Web, visit
        http://www.haskell.org/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.  Getting GHC 7.8.1 (Mathew Phillips)
   2. Re:  Getting GHC 7.8.1 (Henk-Jan van Tuyl)
   3.  Problem with GADTs and Parsec (Lorenzo Tabacchini)
   4. Re:  Problem with GADTs and Parsec (Brandon Allbery)
   5. Re:  Problem with GADTs and Parsec (Brent Yorgey)
   6. Re:  Problem with GADTs and Parsec (Lorenzo)


----------------------------------------------------------------------

Message: 1
Date: Sat, 8 Feb 2014 09:21:53 -0600
From: Mathew Phillips <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Getting GHC 7.8.1
Message-ID:
        <cahukxckttzq8-_mgi3oejx_7rv28b27kq3hmk4+4ggxr55c...@mail.gmail.com>
Content-Type: text/plain; charset="iso-8859-1"

Is there a recommended way to install a newer version of ghc when you
already have the haskell platform installed? I've been reading the
documentation and I can't seem to find anything that shows how to actually
get it other than compiling from source, and I don't want to brick my
current setup if both cant coexist.

Matt P.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140208/ac728f47/attachment-0001.html>

------------------------------

Message: 2
Date: Sat, 08 Feb 2014 18:35:48 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: [email protected], "Mathew Phillips"
        <[email protected]>
Subject: Re: [Haskell-beginners] Getting GHC 7.8.1
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
        delsp=yes

On Sat, 08 Feb 2014 16:21:53 +0100, Mathew Phillips  
<[email protected]> wrote:

> Is there a recommended way to install a newer version of ghc when you
> already have the haskell platform installed? I've been reading the
> documentation and I can't seem to find anything that shows how to  
> actually
> get it other than compiling from source, and I don't want to brick my
> current setup if both cant coexist.
>
> Matt P.

Just install GHC; nothing from the platform is overwritten. Make sure that  
the search path points to the right directories.

Regards,
Henk-Jan van Tuyl


-- 
Folding@home
What if you could share your unused computer power to help find a cure? In  
just 5 minutes you can join the world's biggest networked computer and get  
us closer sooner. Watch the video.
http://folding.stanford.edu/


http://Van.Tuyl.eu/
http://members.chello.nl/hjgtuyl/tourdemonad.html
Haskell programming
--


------------------------------

Message: 3
Date: Sat, 08 Feb 2014 20:10:18 +0100
From: "Lorenzo Tabacchini" <[email protected]>
To: [email protected]
Subject: [Haskell-beginners] Problem with GADTs and Parsec
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"

Hello,
I am developing a very simple programming language for didactic purposes.
Expressions can be composed of different types, like Int, Bool, String etc...
The AST is compiled to JavaScript and the result is shown in the browser.
The code is more or less like this:

{-# LANGUAGE GADTs #-}
data Expr a where
 Int :: Int -> Expr Int
 Bool :: Bool -> Expr Bool
 Text :: String -> Expr String
 -- Int operations
 Add :: Expr Int -> Expr Int -> Expr Int
 -- Bool operations
 And :: Expr Bool -> Expr Bool -> Expr Bool
 -- etc. etc.

-- converts to JavaScript
compile :: Expr a -> String
compile (Int n) = show n
compile (Text t) = show t
compile (Add x y) = compile x ++ "+" ++ compile y
-- etc. etc.

The compilation works perfectly, but I am stuck with the parser.
Since I don't know the types in advance, I would like to parse the whole 
expression at once.
If I do:

exprParser :: Parsec String u (Expr a)
exprParser = parens exprParser
 <|> (reserved "true" >> return (Bool True))
 <|> (reserved "false" >> return (Bool False))
 <|> (stringLiteral >>= return . Text)

The compiler says: "Couldn't match type `Bool' with `[Char]'"

Where am I wrong?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140208/d8d7de97/attachment-0001.html>

------------------------------

Message: 4
Date: Sat, 8 Feb 2014 14:21:36 -0500
From: Brandon Allbery <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
        beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] Problem with GADTs and Parsec
Message-ID:
        <CAKFCL4Wrsc1GLskvNAQv2w3fVqCjTZQkzz+5fVftf+=9j6l...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"

On Sat, Feb 8, 2014 at 2:10 PM, Lorenzo Tabacchini <[email protected]> wrote:

> If I do:
>
> exprParser :: Parsec String u (Expr a)
> exprParser = parens exprParser
>     <|> (reserved "true" >> return (Bool True))
>     <|> (reserved "false" >> return (Bool False))
>     <|> (stringLiteral >>= return . Text)
>
> The compiler says: "Couldn't match type `Bool' with `[Char]'"
> Where am I wrong?
>

The type of exprParser doesn't do what you intend. Specifically, the `a` in
`(Expr a)` is chosen by the *caller* and you have to deal with that choice
somehow --- it does not mean you can pick a different `a` in different
parts of your code.

There are several ways you might redesign your types, but I think I'll have
to let someone else address those.

-- 
brandon s allbery kf8nh                               sine nomine associates
[email protected]                                  [email protected]
unix, openafs, kerberos, infrastructure, xmonad        http://sinenomine.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: 
<http://www.haskell.org/pipermail/beginners/attachments/20140208/fa9a2c21/attachment-0001.html>

------------------------------

Message: 5
Date: Sat, 8 Feb 2014 15:15:19 -0500
From: Brent Yorgey <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Problem with GADTs and Parsec
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii

On Sat, Feb 08, 2014 at 08:10:18PM +0100, Lorenzo Tabacchini wrote:
> 
> exprParser :: Parsec String u (Expr a)
> exprParser = parens exprParser
>  <|> (reserved "true" >> return (Bool True))
>  <|> (reserved "false" >> return (Bool False))
>  <|> (stringLiteral >>= return . Text)

As Brandon explained, this type does not mean what you want: it
promises to be able to return *any* type of Expr, but then it goes and
tries to return *particular* types of Exprs.  Of course, the type is a
lie: you will only be able to return specific types of Exprs, but you
can't know which ones in advance.

In my opinion, this is one of the few places where existential
wrappers are really what you want.  If I were you, I would do
something like this:

  data ExprE where
    ExprE :: Expr a -> ExprE   -- existentially hides the expression type

Now you can write your parser to return an ExprE, with the type of the
expression hidden inside. In order to be able to use the resulting
ExprE values, you will also want a function like

  withExprE :: ExprE -> (Expr a -> r) -> r
  withExprE (ExprE expr) k = k expr

-Brent


------------------------------

Message: 6
Date: Sun, 09 Feb 2014 09:21:15 +0100
From: Lorenzo <[email protected]>
To: [email protected]
Subject: Re: [Haskell-beginners] Problem with GADTs and Parsec
Message-ID: <[email protected]>
Content-Type: text/plain; charset="UTF-8"

> In my opinion, this is one of the few places where existential
> wrappers are really what you want.  If I were you, I would do
> something like this:
> 
>   data ExprE where
>     ExprE :: Expr a -> ExprE   -- existentially hides the expression
> type
> 
> Now you can write your parser to return an ExprE, with the type of the
> expression hidden inside. In order to be able to use the resulting
> ExprE values, you will also want a function like
> 
>   withExprE :: ExprE -> (Expr a -> r) -> r
>   withExprE (ExprE expr) k = k expr

Thanks. This is the kind of solution I was looking for.
The problem is, when I try to access the "hidden" Expr type the compiler
complains:

Couldn't match type `a1' with `a'
      `a1' is a rigid type variable bound by
           a pattern with constructor
             ExprE :: forall a. Expr a -> ExprE,
           in an equation for `withExprE'

      `a' is a rigid type variable bound by
          the type signature for withExprE :: ExprE -> (Expr a -> r) ->
r




------------------------------

Subject: Digest Footer

_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners


------------------------------

End of Beginners Digest, Vol 68, Issue 7
****************************************

Reply via email to