7

Is there a Haskell interpreter that accepts type definitions or preferably all kinds of statements?

I've already tried ghci and hugs and none of these does that. Is there some particular reason that this is hard/impossible?

julx
  • 7,913
  • 5
  • 40
  • 82
  • What are you trying to do? Though I think HBC was able to accept arbitrary Haskell statements. Note that you can't just provide a type definition on its own in ghci as there won't be an attached function for it, though `let f x = x + 1 :: (Num a) => a -> a` should work. – ivanm Oct 11 '11 at 10:28
  • I share your pain. I have tons of `Test.hs` hanging around. Even worse, the ghci console doesn't deal with paste action correctly, at least on my system (bug I just reported). – gawi Oct 11 '11 at 18:01
  • @ivanm Actually, at this moment I'm just starting out and not yet trying to do anything particular. Just got me wondering. – julx Oct 11 '11 at 20:55

2 Answers2

13

It seems that it will soon be fixed in GHCi, see:

https://ghc.haskell.org/trac/ghc/ticket/4929

Chai T. Rex
  • 2,636
  • 1
  • 12
  • 25
Ptival
  • 8,727
  • 32
  • 50
3

Traditionally, the answer to this has been that code written at an interactive prompt lives inside the IO monad. It's as if there's a shadow main = do hiding behind the Prelude>. Think about it that way, and the absence of type declarations and top level declaration syntax makes sense, as do all the let statements.

But Ptival is right: it looks like we won't have to worry about any of that soon.

Zopa
  • 648
  • 4
  • 7