Created
March 4, 2020 21:30
-
-
Save athas/3471f87e5b17c36f26dcf28bf6d75dfc to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| instantiateExtIxFun :: (MonadFreshNames m, Show d, Show u, Show ret) => | |
| Ident -> ExtIxFun -> | |
| m ([PatElemT (MemInfo d u ret)], IxFun) | |
| instantiateExtIxFun idd ext_ixfn = do | |
| let isAndPtps = S.toList $ | |
| foldMap onlyExts $ | |
| foldMap leafExpTypes ext_ixfn | |
| -- Find the existentials that reuse the sizeidents, and | |
| -- those that need new pattern elements. Assumes that the | |
| -- Exts form a contiguous interval of integers. | |
| let (size_exts, new_exts) = | |
| span ((<length sizeidents) . fst) $ sort isAndPtps | |
| (new_substs, patels) <- | |
| fmap unzip $ forM new_exts $ \(i, t) -> do | |
| v <- newVName $ baseString (identName idd) <> "_ixfn" | |
| return ((Ext i, LeafExp (Free v) t), | |
| PatElem v $ MemPrim t) | |
| let size_substs = map (\((i, t), ident) -> | |
| (Ext i, LeafExp (Free (identName ident)) t)) | |
| (zip size_exts sizeidents) | |
| substs = M.fromList $ new_substs <> size_substs | |
| ixfn <- instantiateIxFun $ IxFun.substituteInIxFun substs ext_ixfn | |
| return (patels, ixfn) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment