(;module:
lux
(lux (control monad)
[meta #+ Monad]
(meta (type ["TC" check])))
(luxc ["&" base]
(lang ["la" analysis #+ Analysis])
["&;" scope]))
## [Analysers]
(def: (analyse-definition def-name)
(-> Ident (Meta Analysis))
(do Monad
[actual (meta;find-def-type def-name)
expected meta;expected-type
_ (&;with-type-env
(TC;check expected actual))]
(wrap (#la;Definition def-name))))
(def: (analyse-variable var-name)
(-> Text (Meta (Maybe Analysis)))
(do Monad
[?var (&scope;find var-name)]
(case ?var
(#;Some [actual ref])
(do @
[expected meta;expected-type
_ (&;with-type-env
(TC;check expected actual))]
(wrap (#;Some (#la;Variable ref))))
#;None
(wrap #;None))))
(def: #export (analyse-reference reference)
(-> Ident (Meta Analysis))
(case reference
["" simple-name]
(do Monad
[?var (analyse-variable simple-name)]
(case ?var
(#;Some analysis)
(wrap analysis)
#;None
(do @
[this-module meta;current-module-name]
(analyse-definition [this-module simple-name]))))
_
(analyse-definition reference)))