Timeline for What is the functional programming answer to type-based invariants?
Current License: CC BY-SA 3.0
        16 events
    
    | when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Jun 18, 2015 at 15:44 | audit | Close votes | |||
| Jun 18, 2015 at 15:45 | |||||
| Jun 11, 2015 at 10:25 | audit | Close votes | |||
| Jun 11, 2015 at 10:26 | |||||
| May 26, 2015 at 0:54 | audit | Close votes | |||
| May 26, 2015 at 21:27 | |||||
| May 21, 2015 at 20:51 | vote | accept | Ben Aaronson | ||
| May 21, 2015 at 13:49 | history | tweeted | twitter.com/#!/StackProgrammer/status/601384209186430976 | ||
| May 21, 2015 at 13:29 | answer | added | Michaël Le Barbier | timeline score: 2 | |
| May 21, 2015 at 13:18 | answer | added | Sebastian Redl | timeline score: 6 | |
| May 21, 2015 at 13:08 | comment | added | rwong | @BenAaronson (Since I don't know functional programming, I can't provide an answer, but I can still provide some language-agnostic ideas.) My point is that whenever a new value (instance) is produced, the responsible party is also responsible for: asserting (i.e. taken as truth) whether the invariant is universally upheld or broken; if not asserting, it must request a runtime check on that invariant. Some responsible party must declare this somehow (say, the multiplication operator on ReducedFraction). | |
| May 21, 2015 at 13:01 | comment | added | Ben Aaronson | @rwong Yeah, some nice examples there. I'm actually not 100% clear what ultimate point you're driving at, though. | |
| May 21, 2015 at 12:58 | comment | added | rwong | A seemingly unrelated question, but ... Are asserts or unit tests more important? | |
| May 21, 2015 at 12:55 | answer | added | Karl Bielefeldt | timeline score: 5 | |
| May 21, 2015 at 12:53 | comment | added | rwong | For cases where precondition can't be checked at compile-time, it is idiomatic to check in the constructor. Consider a PrimeNumberclass. It would be too expensive to perform multiple redundant checks for primality for each operation, but it is not a kind of test that can be performed at compile-time.  (A lot of operations you would like to perform on prime numbers, say multiplication, do not form a closure, i.e. results are probably not guaranteed prime. (Posting as comments since I don't know functional programming myself.) | |
| May 21, 2015 at 12:38 | comment | added | Ben Aaronson | @AK_ I'm aware F# can do this (though IIRC it requires some minor hoop-jumping) and guessed Scala could as another cross-paradigm language. Interesting that Haskell can do it- got a link? What I'm really looking for is the functional-idiomatic answer, rather than specific languages which offer a feature. But of course things can get rather fuzzy and subjective once you start talking about what is idiomatic, which is why I left it out of the question. | |
| May 21, 2015 at 12:32 | comment | added | AK_ | many functional languages can do this trivially... Scala, F#, and the other languages that play nicely with OOP, But Haskell too... basically any language that allows you to define types and their behavior supports this. | |
| May 21, 2015 at 12:31 | history | edited | Ben Aaronson | CC BY-SA 3.0 | 
                
                    added 130 characters in body 
                
             | 
| May 21, 2015 at 11:57 | history | asked | Ben Aaronson | CC BY-SA 3.0 |