Re: [Haskell-cafe] Why isn't hsc2hs functionality provided by ghc?

2013-06-04 Thread silly8888
On Tue, Jun 4, 2013 at 10:15 PM, Ivan Lazar Miljenovic
 wrote:
>
> Isn't this done automatically when you have files with the .hsc extension?
>

No, it is not.

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


[Haskell-cafe] Why isn't hsc2hs functionality provided by ghc?

2013-06-04 Thread silly8888
I was wondering today, why hasn't hsc2hs been merged with ghc so that
it would be possible to add a

{-# LANGUAGE ForeignFunctionInterface #-}

at the top of a source file and then load it with ghci or compile it,
without the intermediate step of calling hsc2hs? This would be exactly
like the CPP extension. I don't have to call cpp manually. All I have
to do is to add {-# LANGUAGE CPP #-} and then ghc will take care of
the rest. This would also mean that there would be no need to have a
separate file extension. Surely I must not be the first person to have
that thought, so there must be a good reason why this hasn't happen
yet, but what is it?

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


Re: [Haskell-cafe] parsec: parserFail & multiple error messages

2012-08-09 Thread silly8888
On Thu, Aug 9, 2012 at 3:59 AM, Christian Maeder
 wrote:
> The error message can be improved in your examples by using "count 5"
> instead of "many1".

Yes, I know. That's what I ended up doing. But this is an ad hoc
solution. I think parsec should offer a more general solution.

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


Re: [Haskell-cafe] parsec: parserFail & multiple error messages

2012-08-08 Thread silly8888
Inserting a character into the stream can be expensive if for example
the stream is a ByteString.
I tried the following crazy solution and it seems that it works:

succeed :: Parser ()
succeed = mkPT $ \st ->
return $ Consumed $ return $ Ok () st $ unknownError st

succeed is a parser that always succeeds without really consuming any
input but it also resets the error state.

I really have no understating of how mkPT works. Can someone tell me
if this is a bad idea?

On Wed, Aug 8, 2012 at 4:09 PM, Nick Vanderweit
 wrote:
> I found a similar question asked in June 2009 on the haskell-beginners
> archives, titled "Clearing Parsec error messages." A hack that was proposed
> (http://www.haskell.org/pipermail/beginners/2009-June/001809.html) was to
> insert a dummy character into the stream, consume it, and then fail. Still,
> I'd like to see if there is a cleaner way to modify the error state in the
> Parsec monad.
>
>
> NIck
>
> On Wednesday, August 08, 2012 03:24:31 PM silly wrote:
>> I am trying to create a parsec parser that parses an integer and then
>> checks if that integer has the right size. If not, it generates an
>> error.
>> I tried the following:
>>
>> 8<---
>> import Text.Parsec
>> import Text.Parsec.String
>>
>> integer :: Parser Int
>> integer  = do s <- many1 digit
>>   let n = read s
>>   if n > 65535 then
>>   parserFail "integer overflow"
>>   else
>>   return n
>> 8<---
>>
>> The problem is that when I try this
>>
>> parse integer "" "7"
>>
>> I get the following error:
>>
>> Left (line 1, column 6):
>> unexpected end of input
>> expecting digit
>> integer overflow
>>
>> ie there are three error messages but I only want the last one. Is
>> there something I can do about this?
>>
>> ___
>> Haskell-Cafe mailing list
>> Haskell-Cafe@haskell.org
>> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> ___
> Haskell-Cafe mailing list
> Haskell-Cafe@haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe

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


[Haskell-cafe] parsec: parserFail & multiple error messages

2012-08-08 Thread silly8888
I am trying to create a parsec parser that parses an integer and then
checks if that integer has the right size. If not, it generates an
error.
I tried the following:

8<---
import Text.Parsec
import Text.Parsec.String

integer :: Parser Int
integer  = do s <- many1 digit
  let n = read s
  if n > 65535 then
  parserFail "integer overflow"
  else
  return n
8<---

The problem is that when I try this

parse integer "" "7"

I get the following error:

Left (line 1, column 6):
unexpected end of input
expecting digit
integer overflow

ie there are three error messages but I only want the last one. Is
there something I can do about this?

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