by wellpast · 7y ago · 0 comments
ADTs with non-Maybe fields. I can prove that all is fine if this ‘slot’ isn’t filled in.
Trying to pass an opaque reference down a function call chain.
There’s 3.
> Pattern matching for one. I can prove that 3 cases won’t be met but I have to ‘fill in’ them anyway.
This is a funny one because, no, GHC will not ask you to fill them in! You have to turn on a warning for it to complain. The fact that the warning is not on by default is one of my pet peeves with GHC!
> ADTs with non-Maybe fields. I can prove that all is fine if this ‘slot’ isn’t filled in.
Another funny one, because you can just use `undefined` or `error` and GHC won't complain! Personally I'd probably prefer that it did.
> Trying to pass an opaque reference down a function call chain.
I don't even know what you mean by that.
>> This is a funny one because, no, GHC will not ask you to fill them in! You have to turn on a warning for it to complain. The fact that the warning is not on by default is one of my pet peeves with GHC!
Okay, so let's do the inverse then. I've got a pattern matched case that the type prover proves will never occur (so it throws type error) but I want it to occur.
The answer I know is obvious: I have to add it to the type union. But it should be obvious at this point that the moves I am making are not driven by the outcome I want but by the rules of the type checker. At some point you have to say, Why am I playing these games? Do they really yield tangible, business-facing value?
> ADTs with non-Maybe fields. I can prove that all is fine if this ‘slot’ isn’t filled in.
>>Another funny one, because you can just use `undefined` or `error` and GHC won't complain! Personally I'd probably prefer that it did.
But I don't want an error. I can prove that the absence of the field is OK/not-an-error.
If you say then make it a Maybe, I will tell you sorry I don't have the time to update my entire code-base to contend w/ this novelty to the type checker (I say to the type checker, but this is never a novelty to me and my dynamic code).
> Trying to pass an opaque reference down a function call chain.
>> I don't even know what you mean by that.
my value --(flows at runtime through)--> [some framework, say a web framework code to a, say, a Label that has no idea about my value's type domain] --(flows through pixels to)--> user's eyes
Does Rich Hickey repeat these points somewhere? If so could you point me to where? I'd love to see them. I'm a big fan of Are We There Yet, Simple Made Easy etc. and find Haskell a great implementation of them.
> I have to add it to the type union. But it should be obvious at this point that the moves I am making are not driven by the outcome I want but by the rules of the type checker.
That's not how I see it at all. I wish I could understand why you do see it that way!
> But I don't want an error. I can prove that the absence of the field is OK/not-an-error.
You misunderstand. If you know that a field of a data type is going to be unused you can fill it in with an `error` call that you know will never be hit. You can even omit the field entirely! That's considered bad form but if you like it then knock yourself out.
data Foo = Foo { bar :: Int
, baz :: String
, quux :: Bool
}
doSomething :: Foo -> IO ()
doSomething foo = do
print (bar foo)
print (baz foo)
example1 = Foo { bar = 42
, baz = "Hello"
, quux = error "quux will never be inspected"
}
-- > doSomething example1
-- 42
-- "Hello"
example2 = Foo { bar = 42
, baz = "Hello"
}
-- > doSomething example2
-- 42
-- "Hello"
> my value --(flows at runtime through)--> [some framework, say a web framework code to a, say, a Label that has no idea about my value's type domain] --(flows through pixels to)--> user's eyesWhat's wrong with a polymorphic parameter?
And the response is always “But that’s easy you just do X...”
The argument is not that you can’t do some task in Haskell.
With enough time you can do anything in any language.
That’s the given.
The argument is I want throughput.
If I’m doing X I want to do it because it is necessary to the problem solution.
This is why you hear these laments from Clojure programmers. Because when we code we are doing the minimal amount of work to produce correct programs.
Strongly typed systems add fanfare that Clojure programmers have found no need for.
This is hugely powerful to move very fast in, eg, REPL-driven development environment where you build and verify pieces of code incrementally.
Not being able to do this is a enormous productivity killer, relative to say a dynamic/Clojure.
Sounds like another good candidate for `error` or `undefined`
Wow that sounds really expensive! How did you actually measure that in the real world?
I thought that when I updated a type that all of my running around fixing type errors had to do with me missing something but alas that was not the case. This is how the static enthusiasts do their work, all the while claiming that they are being more productive. When I call a static typer our on this the answer is always the same: "But you'd have to go update those case statements/maybe matches/type signatures anyway!" Meanwhile I'm over in a dynamic system not having to do any of that. Refactors are minimal not cross-the-entire-codebase.
Static type systems are training wheels. When a static type enthusiast takes his training wheels off, the bike falls over and s/he screams "See! I told you. I'm more productive with types!" And then they put the training wheels back on and think that they have proven that static verification is superior. What they don't know is that there is enormous missed opportunity once you learn how to ride a bike w/o training wheels.
The truth is you can produce much faster without a rules-based static type prover between you and your runtime environment if you know what you're doing. This should be obvious b/c in one world you have a filter/prover that you must past to ship. In the other world you do not. If the filter/prover was worth its weight then you should be able to clearly see the win. But in business systems the kinds of bugs found by filter/provers are of the "null pointer" variety -- the fastest and simplest bugs to fix when they are found; having a heavyweight filter/prover save me from these simplest of bugs to fix is simply not worth it.
If you have a place where you consume product types, and you increase the set of fields that you inspect on that sum type, then you do have to cross-the-entire-codebase to update all producers of that product type to emit the new field.
I don't see how it could be any different. How would you handle this in Clojure?