Search Haskell Channel Logs

Sunday, February 19, 2017

#haskell channel featuring barrucadu, monochrom, pyon, roconnor, hpc, hyperthunk_,

Wizek_ 2017-02-19 14:58:54
Is there an online haskell code formatter/beautifier?
Koterpillar 2017-02-19 14:59:52
hindent is an installable one
Wizek_ 2017-02-19 15:02:26
looking into it
stevenxl 2017-02-19 15:09:58
Hi folks. A lot of definitions of a pure function state that a pure function an't depend on reading any hidden value outside of the function scope. Of course, if that's the bar for a pure function, even something like myFunc a b = a + b is not a pure function, since it relies on a value (+) that is not defined in that function's scope.
stevenxl 2017-02-19 15:10:40
I ran into another definition that modifies the "no reading any hidden value..." to say, instead relies on "no external mutable state".
monochrom 2017-02-19 15:10:58
I'm pretty sure "hidden" is wrong. "mutable state variable" is right.
stevenxl 2017-02-19 15:11:07
Under that definition, myFunc a b = a + b is a pure function.
stevenxl 2017-02-19 15:11:14
monochrom: that's what I'm thinking too.
monochrom 2017-02-19 15:11:53
"external" is also wrong. In C "int f(void) { static int i = 0; return i++ }" reads an internal mutable state variable and is clearly impure.
barrucadu 2017-02-19 15:12:43
A nice simple definition is: a pure function always gives the same result for the same argument values.
monochrom 2017-02-19 15:12:48
Actually I think it's all wrong to look at what it does and doesn't read.
stevenxl 2017-02-19 15:12:55
Right.
monochrom 2017-02-19 15:13:00
What barrucadu just said.
stevenxl 2017-02-19 15:13:07
I agree with both of you (monochrom, barrucadu).
hpc 2017-02-19 15:13:09
stevenxl: there's a similar but orthogonal concept of free and bound variables which is what you are thinking of
hpc 2017-02-19 15:13:17
a and b are bound in \a b -> a + b
hpc 2017-02-19 15:13:26
specifically they are bound by the lambda
hpc 2017-02-19 15:13:30
but (+) is free
stevenxl 2017-02-19 15:13:34
The thing is that this definition seems to be pretty pervasive. I found it here: http://scalafp.com/book/definition-of-pure-functions.html
stevenxl 2017-02-19 15:13:44
And on wikipedia
stevenxl 2017-02-19 15:13:44
https://en.wikipedia.org/wiki/Pure_function
hpc 2017-02-19 15:14:00
and a combinator is (iirc) a definition that does not contain any free variables
monochrom 2017-02-19 15:14:13
Pretty sure this is an instance of "misconception is pervasive".
stevenxl 2017-02-19 15:14:21
ok cool.
stevenxl 2017-02-19 15:14:29
This was not letting me rest.
stevenxl 2017-02-19 15:15:12
Because I started thinking about closures, and by that definition, they'd be impure too, even if the closure always returned the same value given the same arguments.
barrucadu 2017-02-19 15:15:45
stevenxl: I think your problem might be a slightly different reading of "hidden value" to what the authors meant. That definition on scalafp.com also says "A pure function depends only on [...] its algorithm to produce its result."
barrucadu 2017-02-19 15:16:00
I would consider the functions that make up another function to be the definition of its algorithm
barrucadu 2017-02-19 15:16:27
And the examples of hidden values that could be read are all state: "Its result can't depend on reading any hidden value outside of the function scope, such as another field in the same class or global variables."
stevenxl 2017-02-19 15:17:04
barrucadu: I see your point yes.
stevenxl 2017-02-19 15:17:53
but I like your definition much better - pure function always returns the same value given the same arguments (plus no side effects)
stevenxl 2017-02-19 15:17:55
:-)
clmg 2017-02-19 15:25:40
How do I get a pure value from an fclabel?
clmg 2017-02-19 15:26:32
nvm
hyperthunk_ 2017-02-19 15:27:37
is this the right place to ask a question about GHC 8.* handling type classes a bit… differently to previous versions!?
roconnor 2017-02-19 15:39:44
I wouldn't say that (+) is free in \a b -> a + b
roconnor 2017-02-19 15:39:52
(+) is a defined constant.
pyon 2017-02-19 15:40:55
QuickCheck question: Is there some way to automatically derive Arbitrary instances?
Koterpillar 2017-02-19 15:42:04
pyon: there are options with TH
Koterpillar 2017-02-19 15:42:22
pyon: https://hackage.haskell.org/package/derive-2.5.26/docs/Data-Derive-Arbitrary.html
pyon 2017-02-19 15:42:30
Koterpillar: Ah, thanks! :-)
Koterpillar 2017-02-19 15:43:17
pyon: also https://hackage.haskell.org/package/generic-random-0.4.0.0/docs/Generic-Random-Generic.html
pyon 2017-02-19 15:44:06
Checking.
Koterpillar 2017-02-19 15:44:12
pyon: https://github.com/nick8325/quickcheck/pull/112