Joachim Breitner's Homepage
Global almost-constants for Haskell
More than five years ago I blogged about the “configuration problem” and a proposed solution for Haskell, which turned into some Template Haskell hacks in the seal-module package.
With the new GHC proposal process in plase, I am suddenly much more inclined to write up my weird wishes for the Haskell language in proposal form, to make them more coherent, get feedback, and maybe (maybe) actually get them implemented. But even if the proposal is rejected it is still a nice forum to discuss these ideas.
So I turned my Template Haskell hack into a proposed new syntactic feature. The idea is shamelessly stolen from Isabelle, including some of the keywords, and would allow you to write
in
context fixes progName foo :: Maybe Int -> Either String Int
Nothing = Left $ progName ++ ": no number given"
foo Just i) = bar i
foo (
bar :: Int -> Either String Int
0 = Left $ progName ++ ": zero no good"
bar = Right $ n + 1 bar n
instead of
foo :: String -> Maybe Int -> Either String Int
Nothing = Left $ progName ++ ": no number given"
foo progName Just i) = bar progName i
foo progName (
bar :: String -> Int -> Either String Int
0 = Left $ progName ++ ": zero no good"
bar progName = Right $ n + 1 bar progName n
when you want to have an “almost constant” parameter.
I am happy to get feedback at the GitHub pull request.
Have something to say? You can post a comment by sending an e-Mail to me at <mail@joachim-breitner.de>, and I will include it here.