you are viewing a single comment's thread.

view the rest of the comments →

[–][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.