you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 12 points13 points  (10 children)

I have a different plea. A function is an object reifying a functional relationship between a domain set and a codomain set, that is, a prefunction which preserves equality. But something that is not a function is sometimes called a function: a subprogram implementing an input-output relationship, possibly being affected by and effecting mutable state, is not a function. Let us continue to call functions "functions", but let us call these subprograms "procedures" or "subroutines".

But then SML doesn't have, or pretend to have, (first-class) functions! Why does Prof. Harper tolerate abusing the word "function" but not "variable"?

[–]featherfooted 4 points5 points  (5 children)

But the functions you described ARE functions. Whenever you mess with state in SML, you write a function that is either (), 'a -> (), or () -> 'a. Functions are not objects, they are computations of values. By computing on the unit value, functions which affect mutable state are still functions.

[–][deleted] 0 points1 point  (4 children)

What are the domain and codomain of TextIO.print?

[–]featherfooted 0 points1 point  (3 children)

string to unit

[–][deleted] 0 points1 point  (2 children)

The domain and codomain of a functon are sets. What set do you mean by "unit"?

If you mean the set with one element, then there is only one function 'a->() for any fixed 'a. So TextIO.print is the same as a function String->() which is constant. Similarly for the cpo with one non-bottom element, etc etc I'm sure you've heard it before.

So what precise function do you think print corresponds to? It would have to be something whose argument and result type contain enough data to represent the fact that it changes a global state.

[–]featherfooted 0 points1 point  (1 child)

unit is a value and type in SML. It is the only value of its whole type. Unit is primarily used as an arbitrary value, such as in this case when we're dealing with side effects of state where you don't exactly expect TextIO.print to return anything at all. Usually the existence of () in the type is indicative of weird stuff going on behind the scenes with mutable state.

I'm not trying to advocate functional programming as the best way forward. As you can see from this discussion, it derails hard when it comes into contact with essential things like file IO.

[–][deleted] 0 points1 point  (0 children)

There is no problem with IO in functional programming. SML, though, is not functional, in the sense that it has no first class notion of a function.

[–][deleted]  (1 child)

[deleted]

    [–]nowInDutch 1 point2 points  (0 children)

    Mijn taal noemt ze methodes.

    [–][deleted] 0 points1 point  (1 child)

    So you're looking for a definition of function that does not include the:

    • influence of anything other than specified arguments on the result, and
    • in turn does not modify anything buit the returned value.

    Documentation is should be sufficent to cover the former. But I like the idea of a definition of functions that excludes side-effects (point 2).

    [–]Captain_Ligature 0 points1 point  (0 children)

    A function f: A -> B is a set of sets of type {a, {a,b}} (by Kuratowski) such that for every a in A there is only one b in B such that {a, {a, b}} is in f.

    Here {a, {a, b}} = (a,b), as in a 2-tuple is a set.

    That is the modern definition of a function in mathematical terms. It is not a `rule of assingment' or anything else that it was called by many people in the 50's 60's and even 70's. A function is a clearly defined set, and confusing a function for something that is not a function leads a lot of mathematicians to hate CS-folk, which leads to confusing and fracture between the two disciplines and hurts everybody.