coalton-lang / coalton

Coalton is an efficient, statically typed functional programming language that supercharges Common Lisp.
https://coalton-lang.github.io/
MIT License
1.12k stars 67 forks source link

(potentially?) broken DO notation #1076

Open stylewarning opened 5 months ago

stylewarning commented 5 months ago
         > Since cs:open? executes when the line (let is-open-b = (cs:open? stream)) executes, is-open-b is calculated before the stream is closed, even though it looks like the stream was already closed on the previous line.

This seems like a bug in our implementation of do to me, though the Haskellers might disagree. It seems to me that

(do
  some-monad
  (let foo = some-pure-computation)
  another-monad)

should expand to something like

(>>= some-monad (fn (_) (let foo = some-pure-computation) another-monad))

whereas at present it expands into

(>>= some-monad
     (coalton::const (coalton::bind foo some-pure-computation another-monad)))

which eagerly evaluates the bind form (imo incorrectly).

Originally posted by @gefjon in https://github.com/coalton-lang/coalton/issues/765#issuecomment-1279755530

stylewarning commented 5 months ago

code for do: https://github.com/coalton-lang/coalton/blob/main/src/codegen/translate-expression.lisp#L754