0

In Haskell in 5 steps the factorial function is defined as follows:

let fac n = if n == 0 then 1 else n * fac (n-1)

But for hugs, it says that fac needs to be in fac.h. Can anyone explain why this is the case - missing the ability to define named functions seems like a massive limitation for an interpreter?

Casebash
  • 114,675
  • 90
  • 247
  • 350
  • 3
    Just FYI, GHCi can define functions. I don't see much reason to be using Hugs these days. – Chuck Mar 30 '10 at 15:26

2 Answers2

2

Hugs misses the ability to define any named functions (recursive or not). It also misses the ability to define data types.

sepp2k
  • 363,768
  • 54
  • 674
  • 675
  • 3
    This says that it has the limitation, not why the limitation exists. –  Mar 30 '10 at 10:34
  • 1
    Thanks for the clarification, but I'm still curious why they decided not to provide this feature. – Casebash Mar 30 '10 at 12:02
2

The basic answer as far as I can tell is that the Hugs interactive toplevel is essentially an expression parser, and function/data definitions are not expressions. Your example actually would work if you made it an expression and wrote let fac n = if n == 0 then 1 else n * fac (n-1) in fac 19. Adding support for this would be a pretty big effort, and apparently the Hugs implementors thought that it was good enough to require function/data definitions to be in files.

Chuck
  • 234,037
  • 30
  • 302
  • 389