Ticket #3302 (closed feature request: fixed)

Opened 4 years ago

Last modified 4 years ago

Where-clause environments for GHCi

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

Description

Often in ghci I'd like to interactively debug and play with functions in the where clause of a top-level definition. Currently, this requires one to change the code, lifting the definitions in question to the top level and adding appropriate parameters.

Given a definition such as

top :: Int -> Int
top x = mult 4 - mult 3 + mult 2
    where
        mult n = x * n

it would be nice to type something such as :environment top 2 to put me in an envrionment where mult is available and mult 4 will evaluate to 8. (Obviously this becomes more useful with more complex definitions.)

Change History

Changed 4 years ago by dherington

It seems what you want is already provided (unless I misunderstand):

bash-3.2$ cat Test.hs top :: Int -> Int top x = mult 4 - mult 3 + mult 2

where

mult n = x * n

bash-3.2$ ghci Test.hs GHCi, version 6.10.3: 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 ( Test.hs, interpreted ) Ok, modules loaded: Main. *Main> :step top 2 Stopped at Test.hs:(2,0)-(4,21) _result :: Int = _ [Test.hs:(2,0)-(4,21)] *Main> :step Stopped at Test.hs:2:8-31 _result :: Int = _ mult :: Int -> Int = _ [Test.hs:2:8-31] *Main> mult 4 8 [Test.hs:2:8-31] *Main>

Changed 4 years ago by dherington

(Sorry, I'm new to Trac and botched the formatting. Trying again...)

bash-3.2$ cat Test.hs
top :: Int -> Int
top x = mult 4 - mult 3 + mult 2
    where
        mult n = x * n
bash-3.2$ ghci Test.hs
GHCi, version 6.10.3: 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             ( Test.hs, interpreted )
Ok, modules loaded: Main.
*Main> :step top 2
Stopped at Test.hs:(2,0)-(4,21)
_result :: Int = _
[Test.hs:(2,0)-(4,21)] *Main> :step
Stopped at Test.hs:2:8-31
_result :: Int = _
mult :: Int -> Int = _
[Test.hs:2:8-31] *Main> mult 4
8
[Test.hs:2:8-31] *Main> 

Changed 4 years ago by igloo

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

Thanks dherington. Closing the ticket as this is already possible.

Note: See TracTickets for help on using tickets.