forked from carp-lang/Carp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Polymorphism.hs
30 lines (25 loc) · 1.11 KB
/
Polymorphism.hs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
module Polymorphism where
import Debug.Trace
import Obj
import Types
import Util
import TypeError
import Lookup
-- | Calculate the full, mangled name of a concretized polymorphic function.
-- | For example, The 'id' in "(id 3)" will become 'id__int'.
-- | This function uses the 'multiLookupALL' function which gives it acces to
-- | modules that are not imported. This allows it to access 'delete' functions
-- | and similar for internal use.
-- | TODO: Environments are passed in different order here!!!
nameOfPolymorphicFunction :: TypeEnv -> Env -> Ty -> String -> Maybe SymPath
nameOfPolymorphicFunction typeEnv env functionType functionName =
let foundBinders = multiLookupALL functionName env
in case filter ((\(Just t') -> areUnifiable functionType t') . ty . binderXObj . snd) foundBinders of
[] -> Nothing
[(_, Binder _ single)] ->
let Just t' = ty single
(SymPath pathStrings name) = getPath single
suffix = polymorphicSuffix t' functionType
concretizedPath = SymPath pathStrings (name ++ suffix)
in Just concretizedPath
_ -> Nothing