3 ms·
Randomly searching for foldr on code.google.com inserts :: [(VarId,VarId)] -> Env -> Env inserts vvs env = foldr (\(a,b) acc -> M.insert a b acc) env v
by pacala 14y ago
Randomly searching for foldr on code.google.com
inserts :: [(VarId,VarId)] -> Env -> Env
inserts vvs env = foldr (\(a,b) acc -> M.insert a b acc) env vvs
or
inserts(vvs, env) {
for ((a, b) : vvs) {
env = M.insert(a, b, env)
}
return env
}
Pick your poison, but I'll stick with fors. Go blues!
- krichman 14y agoIf you want inscrutable Haskell you should go with the <$> operators :) I'd personally still rather have a vvs.reduce(env){|env, (a,b)| M.insert(a, b, env)} but the for loop is perfectly readable also because it fits on a single line. I think for longer bodied reduces I might prefer a for loop actually.