Hacker News new | ask | show | jobs
by dragonwriter 1510 days ago
> Pure functions are pure, yes, but you can have impure functions

Not in Haskell, you can't.

> Haskell is only interesting because you can have impure functions

No, it's interesting because it provides a way of representing series of effectful operations that are distinct from its functions, which are pure.

> otherwise every Haskell program would compile down into a constant

Every program in any language that is compiled compiles down to a constant (which is, itself, usually a program, often an imperative one in a native or virtual machine language); but in Haskell, each program is (in the model of the language, not merely what they compile to) normally a constant, non-function expression, most commonly of type IO ().

It's true that values of type IO a are isomorphic to “impure nullary functions returning a” in a language which has impure functions, but they aren't functions in Haskell, and can't be called from functions, they can only be operated on as values within the language.

1 comments

Haskell's effectful operations are functions. Oh sure, not in the mathematical sense unless you model them as functions from World -> World.

> Every program in any language that is compiled compiles down to a constant ...

Sigh, yes, the compiled program is constant, but you know what I meant: a constant value, such as a number, that the program is expected to output. Let's not be this pedantic.

> Haskell's effectful operations are functions.

No, they aren't.

> Oh sure, not in the mathematical sense unless you model them as functions from World -> World.

Also, not in the syntactical sense.

They are “functions” in that “in certain other programming languages, the closest thing to something filling the same role are called ’functions’.”

But it's rather important to the way Haskell works that they are a different thing that operate at a logically different time, than functions.

> Sigh, yes, the compiled program is constant, but you know what I meant

Yes, you meant reduction, not compilation, and you meant non-function, not just constant, but Haskell programs do reduce to non-function constants.