Hello!
I’m looking for a way that could help me enforce a consistent order of declaration in my own code. I’ve happened to develop a strong taste for the style “declare before use”, I guess my brain works like a sinle-pass compiler
I understand the order of declarations is irrelevant in Haskell due to equational reasoning. But I don’t like to (unecessarily) jump around when reading source code. And overall, I find I make less of a mess when I conform to this kind of constraint.
For reference, this restriction is enforced by the OCaml (and F#) compiler, and can be applied to a TypeScript code base via this eslint rule.
So to sum up, to me, this is okay:
-- 3
wrapHtml content =
"<html><body>" <> content <> "</body></html>"
-- 2
myHtml =
wrapHtml "Hello, world"
-- 1
main =
putStrLn myHtml
This is okay:
-- 1
main =
putStrLn myHtml
-- 2
myHtml =
wrapHtml "Hello, world"
-- 3
wrapHtml content =
"<html><body>" <> content <> "</body></html>"
This is not okay:
-- 2
myHtml =
wrapHtml "Hello, world"
-- 3
wrapHtml content =
"<html><body>" <> content <> "</body></html>"
-- 1
main =
putStrLn myHtml
I’d be interested to hear about possible solutions. If that could help, I’m not looking for something 100% strict btw, I’m fine mixing and matching let clauses with where clauses for instance, at the function scope.