~jojo/Carth

ref: 55fb4f948f1f3797078b584dc60b4f7dd68b37ed Carth/src/FreeVars.hs -rw-r--r-- 614 bytes
55fb4f94JoJo Check `cast` in Infer instead of Gen 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
module FreeVars where

import qualified Data.Set as Set
import Data.Set (Set)

class Ord b => FreeVars a b where
    freeVars :: a -> Set b

fvApp :: FreeVars e t => e -> e -> Set t
fvApp f a = Set.unions (map freeVars [f, a])

fvIf :: FreeVars e t => e -> e -> e -> Set t
fvIf p c a = Set.unions (map freeVars [p, c, a])

fvFun :: FreeVars e t => t -> e -> Set t
fvFun p b = Set.delete p (freeVars b)

fvLet :: (FreeVars a t, FreeVars b t, Foldable f) => ([t], f a) -> b -> Set t
fvLet (bVs, bBs) e = Set.difference
    (Set.union (freeVars e) (foldr (Set.union . freeVars) Set.empty bBs))
    (Set.fromList bVs)