[GHC] #2150: allow definition of functions in the interpreter

GHC trac at galois.com
Thu Mar 13 05:42:47 EDT 2008


#2150: allow definition of functions in the interpreter
-----------------------------+----------------------------------------------
 Reporter:  ahrivera         |          Owner:            
     Type:  feature request  |         Status:  closed    
 Priority:  normal           |      Milestone:            
Component:  GHCi             |        Version:  6.8.2     
 Severity:  normal           |     Resolution:  worksforme
 Keywords:                   |     Difficulty:  Unknown   
 Testcase:                   |   Architecture:  Unknown   
       Os:  Unknown          |  
-----------------------------+----------------------------------------------
Changes (by simonpj):

  * status:  new => closed
  * difficulty:  => Unknown
  * resolution:  => worksforme

Old description:

> Right now, the only way to define functions is through the .hs files.
> Other interpreted languages such as Python allow the user to define
> functions in the command  line.  This is very helpful when one wants to
> prototype some quick functions.
>
> One way to do it could be to detect when one declares the function and
> then enable a mode where one can add definitions.  For example:
>
> Prelude> x:: Int ->Int[[BR]]
>
> *definition*> x a = a + 1[[BR]]
>
> *definition*>[[BR]]
>
> Prelude> x 10[[BR]]
>
> 11[[BR]]
>
> Prelude>[[BR]]
>

> Please consider adding this functionality to GHCI.
>
> Thanks

New description:

 Right now, the only way to define functions is through the .hs files.
 Other interpreted languages such as Python allow the user to define
 functions in the command  line.  This is very helpful when one wants to
 prototype some quick functions.

 One way to do it could be to detect when one declares the function and
 then enable a mode where one can add definitions.  For example:
 {{{
 Prelude> x:: Int ->Int
 *definition*> x a = a + 1
 *definition*>
 Prelude> x 10
 11
 }}}

 Please consider adding this functionality to GHCI.

 Thanks

Comment:

 Happily it's there already:
 {{{
 Prelude> let x a = a+1
 Prelude> x 10
 11
 }}}
 Multi-line definitions are, admittedly, less convenient.  You have to
 write them on one line, but you can use braces and semicolons to put
 multiple lines on one line.
 {{{
 Prelude> let { x::Int -> Int; x a = a+1 }
 }}}

 Perhaps there should be a "mode" as you imply above.  Something like this:
 {{{
 Prelude> let {
 *def*> x a = a+1
 *def*> }
 Prelude>
 }}}
 But the details of such a design are not obvious to me.

 I'll close this since the feature is there.  If it's specifically the
 multi-line thing you want, then open a new ticket for that.

 Simon

-- 
Ticket URL: <http://hackage.haskell.org/trac/ghc/ticket/2150#comment:1>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the Glasgow-haskell-bugs mailing list