4 ms·
> Putting too many functions that are relatively complex in the where clause is a bad idea, because you lose the explicit type signature… Note that it’s possib
by evincarofautumn 10y ago
> Putting too many functions that are relatively complex in the where clause is a bad idea, because you lose the explicit type signature…
Note that it’s possible to give type signatures for definitions in “where” clauses:
twice :: Int -> Int
twice x = two * x
where
two :: Int
two = 2
However, you may need the ScopedTypeVariables extension[1] in order to be able to express the correct type signature. (This extension will probably be standardised at some point.)
The biggest real problem I’ve found with large “where” clauses is that they tend to have a lot of implicit dependencies on variables from the enclosing scope. Sometimes you want that for convenience, readability, or performance, but lifting local definitions out into top-level definitions can also help make them more explicit and reusable.
[1]: https://ocharles.org.uk/blog/guest-posts/2014-12-20-scoped-type-variables.html https://ocharles.org.uk/blog/guest-posts/2014-12-20-scoped-t...
- clusmore 10y ago>The biggest real problem I’ve found with large “where” clauses is that they tend to have a lot of implicit dependencies on variables from the enclosing scope. For me it's always a toss up. I like to make things local where possible to give some indication that the definitions need not be looked over with a fine-toothed comb -- they aren't used extensively. On the other hand, it does often lead to implicit dependencies. It would be nice to have scope highlighting - color every identifier based on the distance from the scope it's defined in. This idea shamelessly stolen from Doug Crockford in https://www.youtube.com/watch?v=b0EF0VTs9Dc https://www.youtube.com/watch?v=b0EF0VTs9Dc
- chriswarbo 10y agoDr Racket has a nice feature where it draws arrows between a variable and its binding site, and between a binding and its use sites; it would be nice to use a similar thing in Haskell. https://docs.racket-lang.org/drracket/buttons.html#%28idx._%28gentag._9._%28lib._scribblings%2Fdrracket%2Fdrracket..scrbl%29%29%29 https://docs.racket-lang.org/drracket/buttons.html#%28idx._%...
- andromeduck 10y agoI think something like eclipse's definition window would do a better job.