fmidue / output-blocks

0 stars 0 forks source link

stricter types to enforce usage pattern #4

Closed jvoigtlaender closed 3 months ago

jvoigtlaender commented 1 year ago

In particular, it seems several types could be made more monomorphic by setting some type variable in part of the input, that is never used, to just ().

Here is an example: https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L211 This function allows usages like translate (return 42).

If instead the type would be specialized to

translate :: OutputMonad m => State (Map Language String) () -> LangM m

then translate (return 42) would not anymore be accepted, but legitimate uses like

translate $ do
  german "abc"
  english "def"

would still be accepted.

By just syntactic inspection of the types, the following functions are candidates for such specialization:

  1. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad-latex/src/Control/Monad/Output/LaTeX.hs#L40-L43
  2. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad-latex/src/Control/Monad/Output/LaTeX.hs#L53
  3. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad-latex/src/Control/Monad/Output/LaTeX.hs#L60
  4. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L211
  5. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L214
  6. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L295-L300
  7. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L303-L308
  8. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L311-L317
  9. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L328-L332
  10. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Report.hs#L50
  11. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Report.hs#L60-L65
  12. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Report.hs#L71-L76
  13. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Report.hs#L90-L96
  14. https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Report.hs#L103-L107
jvoigtlaender commented 1 year ago

Separately, it possibly makes sense to set some "output type parameters" to (), such as the b in https://github.com/fmidue/output-monad/blob/5f494e2bd2b0835254529315bc5886932071c23f/output-monad/src/Control/Monad/Output.hs#L328-L332