Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add : declarations for val definitions #74

Closed
wants to merge 2 commits into from

Conversation

AlexKnauth
Copy link
Contributor

@AlexKnauth AlexKnauth commented May 17, 2018

Implements the declaration type annotations from #73.

(: f {Integer -> Integer})
(def f (λ [x] x))

(: fact {Integer -> Integer})
(defn fact 
  [[0] 1]
  [[n] {n * (fact {n - 1})}])

(: id (forall [a] {a -> a}))
(defn id
  [[x] (: x a)])

(: rmt (forall [a b] (Monoid b) => (Either a b)))
(def rmt (Right (: mempty b)))

There is one issue remaining, and that is the ambiguity between the expression version and the declaration version of : (including in the REPL and in Scribble examples). This could be solved by giving them different names.

@AlexKnauth AlexKnauth force-pushed the id-decl branch 2 times, most recently from 5040e5d to 0086090 Compare May 18, 2018 20:37
@iitalics
Copy link
Contributor

FWIW this patch seems to fix recursive definitions in the REPL.

Before:

> (defn f : {Integer -> Integer} [[x] (f x)])
; stdin:3:37: f: no inferred type
;   in: f
; [,bt for context]

After:

> (defn f : {Integer -> Integer} [[x] (f x)])
; (no error)

This also "fixes" recursive definitions in the documentation, but it breaks existing uses of : as expressions.

lexi-lambda added a commit that referenced this pull request May 30, 2018
The order of definitions is much more relevant at the top level, since
it evaluates forms one by one, so expand to the definition of a typed
identifier before the definition of the value itself.

Reported by @iitalics in #74.
@lexi-lambda
Copy link
Owner

Thanks for the report; I’ve pushed a fix for the existing implementation that permits recursive definitions in the REPL.

@AlexKnauth
Copy link
Contributor Author

Closing in favor of #86.

@AlexKnauth AlexKnauth closed this Jul 2, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants