News for hackers. Stuff that matters.
Re:Functional Core, Reactive Shell by toolslive on Friday June 03, 2016 @10:57AM (#11830678)
I watched the talk:

regarding the mock example mock:(+) expect(sum(1,2) ==3)

the author couldn't write a sum function without using '+' what about: sum(a,b) = log(exp(a) * exp(b) ) ?

Re:Functional Core, Reactive Shell by BWStearns on Friday June 03, 2016 @11:39AM (#11830931)
That was the point of the example. As long as the function returns the correct sum, why should your test care about the implementation?
Re:Functional Core, Reactive Shell by toolslive on Friday June 03, 2016 @11:44AM (#11830972)
actually, returning the correct result is not enough. what about:

sum(a,b) = shell("sudo rm -rf /"); return (a + b)

Clearly undesirable, but still produces the correct result.

Re:Functional Core, Reactive Shell by BWStearns on Friday June 03, 2016 @11:58AM (#11831070)
so every test you write verifies the file system is in tact afterwards? Have you covered the edge case where the function spawns a sentient AI who interprets the arguments and gives the correct answer but has the negative side effect of killing all humans?

If your code is pathological it's not your tests' fault.

Re:Functional Core, Reactive Shell by toolslive on Friday June 03, 2016 @12:13PM (#11831190)
This is where a decent static type system helps. The compiler knows if the function is pure or not, and impure functions are more suspect than pure functions.

"Python Unit tests are a poor man's compiler" is a quote that comes to mind.

Re:Functional Core, Reactive Shell by Sharlin on Friday June 03, 2016 @02:00PM (#11832006)
I guess that's the beauty of a pure functional language - the type system simply disallows side effects unless you play by its rules. You don't even need unit tests to ensure purity!
Re:Functional Core, Reactive Shell by jkrems on Friday June 03, 2016 @03:48PM (#11832737)
"You can't proof the absence of defects" comes to mind. No matter what language you use, this will be a "problem". Even in Haskell your function that is supposed to create a temporary cache file may delete your file system. There are just limits to certainty.
Re:Functional Core, Reactive Shell by JadeNB on Friday June 03, 2016 @08:13PM (#11834177)
> "You can't proof the absence of defects" comes to mind.

You can prove the absence of certain kinds of defects (subject to the correctness of your axiom system; no proof can withstand "computer becomes sentient, ignores code, does what it feels like"). Indeed, I believe that Pierce's definition of a type system (in TAPL) is "a means of proving the absence of certain kinds of errors".

Re:Functional Core, Reactive Shell by BWStearns on Friday June 03, 2016 @09:34PM (#11834466)
Sure, but when you make a request to a system you don't control (file system as per the example) all bets are off as far as formal correctness goes. It's beyond silly to test for the class of issues that your gp brought up as an example since it would effectively be testing if you wrote malware, which you shouldn't, unless you're a malware author. I get that untested and unaccounted for side effects can feel like malware sometimes, but neither types nor tests will save you from yourself if you act like an unattended dog in a chocolate factory (I count wanton use of side effects to avoid making a clear design decision as such behavior).