RE: [Haskell-cafe] Parsec Expected Type

2008-04-07 Thread Paul Keir
Thanks. reservedOp is a better fit; :+ should only be :+.

I also overcame my type issues in an ad-hoc manner, adding

 return ()

whenever I needed to.

-Original Message-
From: Tillmann Rendel [mailto:[EMAIL PROTECTED] 
Sent: 30 March 2008 12:30
To: Paul Keir; haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Parsec Expected Type

Paul Keir wrote: 
 What I'd like is to parse either the string parameter, or the 
 string :. I'm using 'reserved' and 'symbol' because they seem to 
 correspond well to the concepts in the language I'm parsing. 

You may consider using reservedOp for :, depending on how :+ should
be parsed:

  for :+ use reservedOp
  for : + use symbol

If you use reserved, then :name will be parsed as :name not :
name as you probably expect. generally, reserved is for
identifier-like keywords, and reservedOp for operator-like keywords.

 Perhaps I'd express my confusion better if I ask: Why are 'reserved'
 and 'symbol' different types?

I have no idea. They aren't in the Parsec manual on Daans site:

  http://legacy.cs.uu.nl/daan/download/parsec/parsec.html

You can fix this by defining

  reserved name = ParsecToken.reserved tokenParser name  return name

instead of

  reserved = ParsecToken.reserved tokenParser

to import the reserved component from the tokenParser to the toplevel.
Now,

  reserved :: String - CharParser st String

Another option is to fix it the other way, by defining

  symbol name = ParsecToken.symbol tokenParser name  return ()

or to fix it in a ad-hoc manner, by defining

  ignored = ( return ())

and using it in the approbiate places, like

  parameterOrColon = reserved parameter | ignored (symbol :)

Tillmann
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec Expected Type

2008-03-30 Thread Tillmann Rendel
Paul Keir wrote: 
 What I'd like is to parse either the string parameter, or the 
 string :. I'm using 'reserved' and 'symbol' because they seem to 
 correspond well to the concepts in the language I'm parsing. 

You may consider using reservedOp for :, depending on how :+ should be 
parsed:

  for :+ use reservedOp
  for : + use symbol

If you use reserved, then :name will be parsed as :name not : name as 
you probably expect. generally, reserved is for identifier-like keywords, and 
reservedOp for operator-like keywords.

 Perhaps I'd express my confusion better if I ask: Why are 'reserved'
 and 'symbol' different types?

I have no idea. They aren't in the Parsec manual on Daans site:

  http://legacy.cs.uu.nl/daan/download/parsec/parsec.html

You can fix this by defining

  reserved name = ParsecToken.reserved tokenParser name  return name

instead of

  reserved = ParsecToken.reserved tokenParser

to import the reserved component from the tokenParser to the toplevel.
Now,

  reserved :: String - CharParser st String

Another option is to fix it the other way, by defining

  symbol name = ParsecToken.symbol tokenParser name  return ()

or to fix it in a ad-hoc manner, by defining

  ignored = ( return ())

and using it in the approbiate places, like

  parameterOrColon = reserved parameter | ignored (symbol :)

Tillmann
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Parsec Expected Type

2008-03-29 Thread Paul Keir
Many thanks guys, you've really taught me how to catch a fish here!
Paul


-Original Message-
From: Brandon S. Allbery KF8NH [mailto:[EMAIL PROTECTED]
Sent: Sat 3/29/2008 1:41 AM
To: haskell-cafe@haskell.org Cafe
Cc: Paul Keir
Subject: Re: [Haskell-cafe] Parsec Expected Type
 

On Mar 28, 2008, at 21:12 , Ryan Ingram wrote:
 On 3/28/08, Paul Keir [EMAIL PROTECTED] wrote:
 What I'd like is to parse either the string parameter, or the  
 string :.
 I'm using 'reserved' and 'symbol' because they seem to correspond  
 well to
 the concepts in the language I'm parsing. I could try,

 tester3 = reserved parameter | do { symbol :; return () }

 Or you could factor this behavior out into a new combinator:

 or_ :: Parser a - Parser b - Parser ()
 or_ x y = (x  return ()) | (y  return ())

 tester3 = reserved parameter `or_` symbol :

Or if you'd like to be inscrutable:

import Data.Function

or_ = ( return ()) `on` (|)

-- 
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH



___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Paul Keir
Thanks, I'd thought it was something to do with incompatible types. I can now 
create a simpler problem:

tester2 = reserved parameter | symbol :

Certainly I could use reserved : instead of symbol, but where is my thinking 
with symbol here going wrong? Surely the above example isn't so odd?

Paul


-Original Message-
From: Luke Palmer [mailto:[EMAIL PROTECTED]
Sent: Fri 3/28/2008 12:26 AM
To: Paul Keir
Cc: haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Parsec Expected Type
 
Hi Paul,

2008/3/27 Paul Keir [EMAIL PROTECTED]:
 Hi,

  Does anyone know why this reduced Parsec production stops compilation, and
 how I can fix it?

  tester = reserved parameter
   | do { reserved dimension; symbol : }

Look at the types of reserved and symbol (from
http://www.haskell.org/ghc/docs/latest/html/libraries/parsec/Text-ParserCombinators-Parsec-Token.html):

  symbol :: String - CharParser st String
  reserved :: String - CharParser st ()

The type of a do block is the same as the type of its last statement.
But (reserved parameter) and (symbol ;) do not have the same type.

Luke

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Jonathan Cast

On 28 Mar 2008, at 2:02 AM, Paul Keir wrote:

Thanks, I'd thought it was something to do with incompatible types.  
I can now create a simpler problem:


tester2 = reserved parameter | symbol :

Certainly I could use reserved : instead of symbol, but where is  
my thinking with symbol here going wrong? Surely the above example  
isn't so odd?



What type do you expect tester2 to return?

jcc

___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


RE: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Paul Keir
Could tester2 return some kind of base type, which the two inherit from? I 
don't know. I'm really only presenting the ugly tester2 function because I'm 
looking for a Parsec-concordant solution to what appears a simple problem.

What I'd like is to parse either the string parameter, or the string :. I'm 
using 'reserved' and 'symbol' because they seem to correspond well to the 
concepts in the language I'm parsing. I could try,

tester3 = reserved parameter | do { symbol :; return () }

but that's feels a bit contrived; or I could use 'reserved' twice.

Perhaps I'd express my confusion better if I ask: Why are 'reserved' and 
'symbol' different types?

Paul (Haskell Novice)




-Original Message-
From: Jonathan Cast [mailto:[EMAIL PROTECTED]
Sent: Fri 3/28/2008 2:05 PM
To: Paul Keir
Cc: Luke Palmer; haskell-cafe@haskell.org
Subject: Re: [Haskell-cafe] Parsec Expected Type
 
On 28 Mar 2008, at 2:02 AM, Paul Keir wrote:

 Thanks, I'd thought it was something to do with incompatible types.  
 I can now create a simpler problem:

 tester2 = reserved parameter | symbol :

 Certainly I could use reserved : instead of symbol, but where is  
 my thinking with symbol here going wrong? Surely the above example  
 isn't so odd?

What type do you expect tester2 to return?

jcc


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Ryan Ingram
On 3/28/08, Paul Keir [EMAIL PROTECTED] wrote:
 What I'd like is to parse either the string parameter, or the string :.
 I'm using 'reserved' and 'symbol' because they seem to correspond well to
 the concepts in the language I'm parsing. I could try,

 tester3 = reserved parameter | do { symbol :; return () }

Actually this is exactly on the right track.  But I agree, it looks a
bit contrived.  Maybe this looks better to you?

 tester3 = reserved parameter | (symbol :  return ())

Or you could factor this behavior out into a new combinator:

 or_ :: Parser a - Parser b - Parser ()
 or_ x y = (x  return ()) | (y  return ())

 tester3 = reserved parameter `or_` symbol :

  -- ryan
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec Expected Type

2008-03-28 Thread Brandon S. Allbery KF8NH


On Mar 28, 2008, at 21:12 , Ryan Ingram wrote:

On 3/28/08, Paul Keir [EMAIL PROTECTED] wrote:
What I'd like is to parse either the string parameter, or the  
string :.
I'm using 'reserved' and 'symbol' because they seem to correspond  
well to

the concepts in the language I'm parsing. I could try,

tester3 = reserved parameter | do { symbol :; return () }


Or you could factor this behavior out into a new combinator:


or_ :: Parser a - Parser b - Parser ()
or_ x y = (x  return ()) | (y  return ())



tester3 = reserved parameter `or_` symbol :


Or if you'd like to be inscrutable:

import Data.Function

or_ = ( return ()) `on` (|)

--
brandon s. allbery [solaris,freebsd,perl,pugs,haskell] [EMAIL PROTECTED]
system administrator [openafs,heimdal,too many hats] [EMAIL PROTECTED]
electrical and computer engineering, carnegie mellon universityKF8NH


___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe


Re: [Haskell-cafe] Parsec Expected Type

2008-03-27 Thread Luke Palmer
Hi Paul,

2008/3/27 Paul Keir [EMAIL PROTECTED]:
 Hi,

  Does anyone know why this reduced Parsec production stops compilation, and
 how I can fix it?

  tester = reserved parameter
   | do { reserved dimension; symbol : }

Look at the types of reserved and symbol (from
http://www.haskell.org/ghc/docs/latest/html/libraries/parsec/Text-ParserCombinators-Parsec-Token.html):

  symbol :: String - CharParser st String
  reserved :: String - CharParser st ()

The type of a do block is the same as the type of its last statement.
But (reserved parameter) and (symbol ;) do not have the same type.

Luke
___
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe