Re: [Haskell-cafe] ghc -e

2010-01-13 Thread Henning Thielemann


On Wed, 6 Jan 2010, Gwern Branwen wrote:


On Wed, Jan 6, 2010 at 7:23 PM, Tony Morris  wrote:

ghc -e "import Control.Monad; forM [[1,2,3]] reverse"


As of 6.10.2, the bug whereby the GHC API lets you use functions from
anywhere just by naming them (Java-style) has not been fixed:

$ ghc -e "Control.Monad.forM [[1,2,3]] reverse"
package flags have changed, resetting and loading new packages...


Why is this a bug? This is the intended behaviour in GHCi and you can 
include and exclude packages with -package and -hide-package options, 
respectively.

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


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Jason Dagit
On Wed, Jan 6, 2010 at 6:15 PM, Reid Barton wrote:

> On Thu, Jan 07, 2010 at 10:23:35AM +1000, Tony Morris wrote:
> > Can I import a module when using ghc -e?
> >
> > e.g. ghc -e "import Control.Monad; forM [[1,2,3]] reverse"
>
> One option is to create a file "imports.hs" which contains the text
> "import Control.Monad", and then run
>
> ghc -e "forM [[1,2,3]] reverse" imports.hs
>
> I use this method in a short shell script "interact" so that I can
> apply Haskell functions to files from the command line and don't have
> to type the full qualified names of things in modules I use frequently.
>

Did you know you can put commands in $HOME/.ghci that will be loaded every
time you run ghci?

So, if you have modules that you commonly use put something like:
:m + Control.Monad

In your $HOME/.ghci file and then you can use ghci instead of this ghc -e
trick.

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


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Gwern Branwen
On Wed, Jan 6, 2010 at 7:35 PM, Tony Morris  wrote:
> Gwern Branwen wrote:
>> On Wed, Jan 6, 2010 at 7:23 PM, Tony Morris  wrote:
>>
>>> ghc -e "import Control.Monad; forM [[1,2,3]] reverse"
>>>
>>
>> As of 6.10.2, the bug whereby the GHC API lets you use functions from
>> anywhere just by naming them (Java-style) has not been fixed:
>>
>> $ ghc -e "Control.Monad.forM [[1,2,3]] reverse"
>> package flags have changed, resetting and loading new packages...
>>
>> :1:25:
>>     Warning: Defaulting the following constraint(s) to type `Integer'
>>              `Num t' arising from the literal `3' at :1:25
>>     In the expression: 3
>>     In the expression: [1, 2, 3]
>>     In the first argument of `forM', namely `[[1, 2, 3]]'
>>
>> :1:25:
>>     Warning: Defaulting the following constraint(s) to type `Integer'
>>              `Num t' arising from the literal `3' at :1:25
>>     In the expression: 3
>>     In the expression: [1, 2, 3]
>>     In the first argument of `forM', namely `[[1, 2, 3]]'
>> [[3],[2],[1]]
>> it :: [[Integer]]
>> (0.01 secs, 1710984 bytes)
>>
>>
> I see the same on GHC 6.10.4.
> $ ghc -e "Control.Monad.forM [[1,2,3]] reverse"
> [[3],[2],[1]]
>
>
> What would it be fixed to? What is wrong with how it is?

Presumably one then have to use some sort of flag to ask for
Control.Monad specifically to be visible.

What's wrong with it is that this is not merely GHCi behavior, this is
universal GHC API behavior and wildly insecure:
http://hackage.haskell.org/trac/ghc/ticket/2452

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


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Reid Barton
On Thu, Jan 07, 2010 at 10:23:35AM +1000, Tony Morris wrote:
> Can I import a module when using ghc -e?
> 
> e.g. ghc -e "import Control.Monad; forM [[1,2,3]] reverse"

One option is to create a file "imports.hs" which contains the text
"import Control.Monad", and then run

ghc -e "forM [[1,2,3]] reverse" imports.hs

I use this method in a short shell script "interact" so that I can
apply Haskell functions to files from the command line and don't have
to type the full qualified names of things in modules I use frequently.

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


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Tony Morris
Gwern Branwen wrote:
> On Wed, Jan 6, 2010 at 7:23 PM, Tony Morris  wrote:
>   
>> ghc -e "import Control.Monad; forM [[1,2,3]] reverse"
>> 
>
> As of 6.10.2, the bug whereby the GHC API lets you use functions from
> anywhere just by naming them (Java-style) has not been fixed:
>
> $ ghc -e "Control.Monad.forM [[1,2,3]] reverse"
> package flags have changed, resetting and loading new packages...
>
> :1:25:
> Warning: Defaulting the following constraint(s) to type `Integer'
>  `Num t' arising from the literal `3' at :1:25
> In the expression: 3
> In the expression: [1, 2, 3]
> In the first argument of `forM', namely `[[1, 2, 3]]'
>
> :1:25:
> Warning: Defaulting the following constraint(s) to type `Integer'
>  `Num t' arising from the literal `3' at :1:25
> In the expression: 3
> In the expression: [1, 2, 3]
> In the first argument of `forM', namely `[[1, 2, 3]]'
> [[3],[2],[1]]
> it :: [[Integer]]
> (0.01 secs, 1710984 bytes)
>
>   
I see the same on GHC 6.10.4.
$ ghc -e "Control.Monad.forM [[1,2,3]] reverse"
[[3],[2],[1]]


What would it be fixed to? What is wrong with how it is?

-- 
Tony Morris
http://tmorris.net/


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


Re: [Haskell-cafe] ghc -e

2010-01-06 Thread Gwern Branwen
On Wed, Jan 6, 2010 at 7:23 PM, Tony Morris  wrote:
> ghc -e "import Control.Monad; forM [[1,2,3]] reverse"

As of 6.10.2, the bug whereby the GHC API lets you use functions from
anywhere just by naming them (Java-style) has not been fixed:

$ ghc -e "Control.Monad.forM [[1,2,3]] reverse"
package flags have changed, resetting and loading new packages...

:1:25:
Warning: Defaulting the following constraint(s) to type `Integer'
 `Num t' arising from the literal `3' at :1:25
In the expression: 3
In the expression: [1, 2, 3]
In the first argument of `forM', namely `[[1, 2, 3]]'

:1:25:
Warning: Defaulting the following constraint(s) to type `Integer'
 `Num t' arising from the literal `3' at :1:25
In the expression: 3
In the expression: [1, 2, 3]
In the first argument of `forM', namely `[[1, 2, 3]]'
[[3],[2],[1]]
it :: [[Integer]]
(0.01 secs, 1710984 bytes)

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


[Haskell-cafe] ghc -e

2010-01-06 Thread Tony Morris
Can I import a module when using ghc -e?

e.g. ghc -e "import Control.Monad; forM [[1,2,3]] reverse"

-- 
Tony Morris
http://tmorris.net/

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


Re: [Haskell-cafe] ghc -e with standard input

2007-11-05 Thread Rodrigo Queiro
interact :: (String -> String) -> IO () is a very handy function for
ghc -e, e.g.

ghc -e 'interact $ lines . map (show . (*2) . read) . unlines'

will multiply the number on every line by 2. (interact takes a
function which maps from entire input to entire output)

On 05/11/2007, Graham Fawcett <[EMAIL PROTECTED]> wrote:
> On Nov 5, 2007 1:46 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Is there a way to run 'ghc -e' taking input
> > from standard input? I would like to use it
> > in a pipe.
>
> It seems to me that you can use getContents, et. al., as you would
> from any other Haskell program:
>
> $ echo hello there mauricio | ghc -e "print =<< (Control.Monad.liftM
> (reverse . words)) getContents"
> ["mauricio","there","hello"]
>
> G
> ___
> 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


Re: [Haskell-cafe] ghc -e with standard input

2007-11-05 Thread Brent Yorgey
On Nov 5, 2007 2:41 PM, Graham Fawcett <[EMAIL PROTECTED]> wrote:

> On Nov 5, 2007 1:46 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
> > Hi,
> >
> > Is there a way to run 'ghc -e' taking input
> > from standard input? I would like to use it
> > in a pipe.
>
> It seems to me that you can use getContents, et. al., as you would
> from any other Haskell program:
>
> $ echo hello there mauricio | ghc -e "print =<< (Control.Monad.liftM
> (reverse . words)) getContents"
> ["mauricio","there","hello"]
>

hm, which raises the question of exactly what Maurí­cio meant.  Maurí­cio,
if you mean you want to do ghc -e "some code which gets its data from
standard input", then Graham's solution is exactly what you want.  If you
mean you want to have ghc -e run some code which itself comes from standard
input, then you want xargs (just do a man xargs to see how to use it).  In
retrospect I'm guessing that Graham answered your real question...? =)

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


Re: [Haskell-cafe] ghc -e with standard input

2007-11-05 Thread Graham Fawcett
On Nov 5, 2007 1:46 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:
> Hi,
>
> Is there a way to run 'ghc -e' taking input
> from standard input? I would like to use it
> in a pipe.

It seems to me that you can use getContents, et. al., as you would
from any other Haskell program:

$ echo hello there mauricio | ghc -e "print =<< (Control.Monad.liftM
(reverse . words)) getContents"
["mauricio","there","hello"]

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


Re: [Haskell-cafe] ghc -e with standard input

2007-11-05 Thread Brent Yorgey
On Nov 5, 2007 1:46 PM, Maurí­cio <[EMAIL PROTECTED]> wrote:

> Hi,
>
> Is there a way to run 'ghc -e' taking input
> from standard input? I would like to use it
> in a pipe.
>

xargs ought to do the trick nicely.

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


[Haskell-cafe] ghc -e with standard input

2007-11-05 Thread Maurí­cio

Hi,

Is there a way to run 'ghc -e' taking input
from standard input? I would like to use it
in a pipe.

Thanks,
Maurício

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