views:

104

answers:

3

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).

+4  A: 

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

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

sepp2k
+3  A: 

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

sclv
Nice to know this.
FUZxxl
+1  A: 

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.

Don Stewart
It would need changes deeper in GHC I think; the GHC API doesn't provide enough functionality yet to implement this on top of it. It's not that difficult, just work.
Simon Marlow