Ticket #2400 (closed bug: invalid)

Opened 5 years ago

Last modified 5 years ago

location-dependent scope issue with ghci.conf

Reported by: claus Owned by:
Priority: normal Milestone:
Component: GHCi Version: 6.9
Keywords: Cc:
Operating System: Windows Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I recently noticed some of my ghci.conf commands going wrong in newer GHCis, and have now reduced the issue to this tiny example, which ceases to work when moved from a locally sourced script to the main ghci.conf location:

$ cat $HOME/.ghci
cat: /home/cr3/.ghci: No such file or directory

$ cat ./.ghci
cat: ./.ghci: No such file or directory

$ cat /cygdrive/c/Documents\ and\ Settings/cr3/Application\ Data/ghc/ghci.conf
let { msg () = "done" ; grep _ = return $ unlines ["let x=()","putStrLn (msg x)"] }

:def grep grep


$ cat U.hs


$ /cygdrive/c/ghc/ghc-6.9.20080514/bin/ghcii.sh U.hs
GHCi, version 6.9.20080514: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( U.hs, interpreted )
Ok, modules loaded: Main.
*Main> :grep x

<interactive>:1:10: Not in scope: `msg'
*Main> msg ()

<interactive>:1:0: Not in scope: `msg'
*Main> :q
Leaving GHCi.

$ cp /cygdrive/c/Documents\ and\ Settings/cr3/Application\ Data/ghc/ghci.conf .

$ cat ghci.conf
let { msg () = "done" ; grep _ = return $ unlines ["let x=()","putStrLn (msg x)"] }

:def grep grep


$ /cygdrive/c/ghc/ghc-6.9.20080514/bin/ghcii.sh U.hs -ignore-dot-ghci
GHCi, version 6.9.20080514: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer ... linking ... done.
Loading package base ... linking ... done.
[1 of 1] Compiling Main             ( U.hs, interpreted )
Ok, modules loaded: Main.
*Main> :grep
unknown command ':grep'
use :? for help.
*Main> :cmd readFile "ghci.conf"
*Main> :grep x
done
*Main> msg ()
"done"

Change History

Changed 5 years ago by simonmar

  • status changed from new to closed
  • difficulty set to Unknown
  • resolution set to invalid

This doesn't look like a bug to me. Existing bindings are discarded when a module is loaded, so the binding msg is not available after loading Main. To avoid this you need to refer to msg by name rather than by a string, i.e. bind it at the time grep is defined, rather than when grep is run.

Changed 5 years ago by claus

Hm, I'm sure I tested this against older GHCi versions at the time (the example is a stripped down version of the real .ghci/ghci.conf I've been using for quite some time). But I can't seem to reproduce a working version with older GHCis now, so closing is right.

You probably meant it the other way round: bind msg at the time grep is run, rather than defined. Thanks, that also works in the current version of my full script, but prevents reuse of the function represented here by msg in other commands (cross-stage persistence in GHCi scripts is tricky, not least because of the awkward syntax).

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.