Plan 9 from Bell Labs’s /usr/web/sources/contrib/fernan/nhc98/src/compiler98/Core/Reduce.hs

Copyright © 2021 Plan 9 Foundation.
Distributed under the MIT License.
Download the Plan 9 distribution.



module Core.Reduce(reduce) where

import Core.CoreType
import List

reduce (Core x) = Core $ map f x

f (CoreFunc a b) = CoreFunc a (red b)

red (CoreCon x) = CoreCon (redName x)
red (CoreVar x) = CoreVar (redName x)
red (CoreApp x y) = CoreApp (red x) (map red y)
red (CoreCase x y) = CoreCase (red x) (map (\(a,b) -> (red a, red b)) y)
red (CoreLet x y) = CoreLet (map f x) (red y)
red (CorePos x y) = CorePos x (red y)
red x = x


aliases = [
    ("Prelude.Prelude.Eq.Prelude.", ""),
    ("Prelude.Prelude.Num.Prelude.", ""),
    ("Prelude.","")
    ]

redName x = g aliases
    where
        g ((find,rep):xs) | find `isPrefixOf` x = rep ++ drop (length find) x
                          | otherwise = g xs
        g [] = x

Bell Labs OSI certified Powered by Plan 9

(Return to Plan 9 Home Page)

Copyright © 2021 Plan 9 Foundation. All Rights Reserved.
Comments to webmaster@9p.io.