Just goes to show, our intuition works on linear types.
Just goes to show, our intuition works on linear types.
def get_my_age():
return 21
The students' reaction to this in office hours can be... interesting. I am curious how many of them actually follow the comment at the bottom of the question, and what they think:> Reflect on the difference between creating a variable with a constant value and creating a function with no arguments and a constant return value.
Up to you to decide if this has any pedagogical value. The real learning objective was to "write a function that has no arguments but returns a constant value", so getting them to draw big conclusions about the nature of functions and values and so on is outside the scope of this little activity.
This is - or at least might be - ambiguous. Current age as of implementation time or current age as of function invocation time? And while a result in whole years is a pretty natural and obvious choice for the age of a person in absence of an explicit requirement, it is certainly not the only sensible choice.
Expressing "age" in whole years is acceptable in English, but using a decimal would be highly defensible. That's an issue of grading though.
This is a problem I have with certain parts of computer science and math education. Everything is encouraged to be exact, then, suddenly, variable names are used inconsistently, niche cases are ignored arbitrarily and explained with essentially referring to "common sense".
Software engineering is all about mapping dirty nuance to formal systems.
use constant PI => 4 * atan2(1, 1);
under the hood becomes sub PI () { 4 * atan2 1, 1 }
http://perldoc.perl.org/constant.html#TECHNICAL-NOTES>> I think he was just stuck on the idea of the function doing something arithmetical to the input, and was having trouble coming up with some sort of arithmetic procedure which would result in 6 no matter what you put in
don't really seem, to me, like they can explain what's happening -- f(x) = 6 is trivially easy to express in terms of arithmetic operations being applied to x. If you assume that a function that multiplies by 2 is intuitively ok, what's wrong with a function that multiplies by 0?
f(x) = 0*x + 6
EDIT: Or even, if multiplication is a problem, f(x) = (x - x) + 6
Obviously the fact that it doesn't seem to have any visible effect on the input -- and people expect the input to be affected.
Your comment is more of an indictment of identity functions than dimension-losing functions.
If you don't act on the input, you have an identity function, not a constant function. Constant functions must alter their input whenever it doesn't match the constant output. Nobody ever complained that the problem with Procrustes was that he didn't do anything to the guests in his bed.
And in the other direction, I don't understand why you want to characterize "multiply the input by zero" as an action that "doesn't do anything"? In what sense would that be true?
const :: a -> b -> a
const a _ = a
f' :: a -> ()
f' = const ()
Now I can give `f'` anything at all. Can you try to explain the action of `f'` in any way but that it ignores its argument?Easily:
f(x) = 20
No action on the input -- discarding the input is not an intuitive action for a 6-year old that just got a handful of of ax+k and xk + n style examples.
>Nobody ever complained that the problem with Procrustes was that he didn't do anything to the guests in his bed.*
You seem confused. Procrustes operated on his guests, which is neither the identity (they would come of unscratched) or the constant function (in which the same person or thing would emerge out of the bed).
Their height in the end was the same, but that's not the argument to the Procrustes function -- their overall body was.
>And in the other direction, I don't understand why you want to characterize "multiply the input by zero" as an action that "doesn't do anything"? In what sense would that be true?
Obviously in the intuitive sense for a 6-year old -- which is what we're discussing, and which was based on some operation on the argument that resulted in a different value each time, not degenerate versions of functions like the identity, constant, 0, etc.
(That said, it "doesn't do anything to the input" in the sense that it's not dependent on the particular input. 2x gives you 4 and 10 if you pass 2 and 5. 0x gives you 0 whatever you pass it, so could just as well be a constant fx = 0).
Fixed, for the sake of corresponding more exactly with the challenge. Not that it wasn't clear what you meant :)
It wasn't "what would the result be" that eluded the child (or those students).
It was the question "in what way is this an operation on x" -- which in their minds was intuitively, put x in and add/subtract/multiply by something(s) to get another result.
fx=K, fx=0, or fx=x didn't seem as substantial enough transformations (given the other examples) to qualify with their notion of a function.
So, is it that it is linearly typed, or that it is greedy and wants to use all inputs given at least once?
Or, are those the same thing?
But, your statement is true for all real-valued linear functions AFAIK.
In finite dimension however linear functions are continuous
So much for teaching year olds. This is not rocket science, but mathematicians (almost inherent) inability to have language skills makes it seem so, notably.
same but different:
6+x/a, a->infinity
imho constant is a special case of linear