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