Question

While commenting on new features in ghci I wished that ghci had the ability to declare type declaration and declaring new ADT types, someone informed that it was indeed possible, and after searching I found this page which told me I could do

let numUniques' :: (Eq a) => [a] -> Int; numUniques' = length . nub

Apparently that same sort of syntax works for pattern matching (ex. let a 1=True;a 2=False).

Creating ADTs would make it almost perfect? Does anyone know if it is currently possible? Should I just make an ADT scratch file and reload it?

P.S. Does anyone know if there are any plans to do so? Are there feature requests for ghc(i)?

Also I know its open source but I'm not currently smart enough to hack on ghc(i).

Was it helpful?

Solution

No, but you could define new types in hbi (an earlier interpreter). There's discussion about bringing this back, via a ghci library on hackage.

OTHER TIPS

Note that you can also do explicit multiline code in ghci with :{ and :}: http://www.haskell.org/ghc/docs/6.12.2/html/users_guide/interactive-evaluation.html

This has been added as of GHC version 7.4.1, which was released back in February:

jcp@butler:~$ ghci
GHCi, version 7.6.1: http://www.haskell.org/ghc/  :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> data Test = Foo | Bar | Baz deriving (Read, Show)
Prelude> Foo
Foo
Prelude> read "Bar" :: Test
Bar
Prelude> :t Baz
Baz :: Test

No, you can't define new types in ghci.

So yes, you'll need to put those definitions in a file.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top