Skip to content

Instantly share code, notes, and snippets.

@awave1
Created February 27, 2020 00:28
Show Gist options
  • Select an option

  • Save awave1/ae40db8e7cd093d745e1c78d2ddedfa9 to your computer and use it in GitHub Desktop.

Select an option

Save awave1/ae40db8e7cd093d745e1c78d2ddedfa9 to your computer and use it in GitHub Desktop.
state thing a
thing -> (thing, a)
b -> state thing a

Alpha Renaming w/ State Monad

Given [Fun] -> State (int, int) Fun:

xs = do
  (fn, vn) <- get -- getting the state
  let vs = zip (fun.symbols xs) [v..] -- [(n, f'1),... (n+m, f'm)]
  {-
   given [(n, f'1),... (n+m, f'm)] and [f1, f2, f3, ..., fm]
   for each f take its funciton name and replace it with new name using the substitude_f
  -}
  let new_funs = foldr (\sub funs -> map (substitute_f sub) funs) vs

substitute_f :: (String, Int) -> Fun -> Fun
substitute_f = undefined

plusplus :: State int int -- gives back the current, incrementing the other

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment