packages feed

funcons-tools-0.1.0.0: cbs/Funcons/Core/Computations/DataFlow/Linking/FollowIfLink.hs

-- GeNeRaTeD fOr: ../../CBS/Funcons/Computations/Data flow/Linking/follow-if-link.aterm
{-# LANGUAGE OverloadedStrings #-}

module Funcons.Core.Computations.DataFlow.Linking.FollowIfLink where

import Funcons.EDSL

entities = []

types = typeEnvFromList
    []

funcons = libFromList
    [("follow-if-link",StrictFuncon stepFollow_if_link)]

-- |
-- If /V/ is a link, then /follow-if-link(V)/ gives the value
--   to which the link /V/ has been set.  Otherwise, /V/ is returned.
follow_if_link_ fargs = FApp "follow-if-link" (FTuple fargs)
stepFollow_if_link fargs =
    evalRules [rewrite1,rewrite2] []
    where rewrite1 = do
            let env = emptyEnv
            env <- vsMatch fargs [VPMetaVar "V"] env
            env <- sideCondition (SCIsInSort (TVar "V") (TName "all-links")) env
            rewriteTermTo (TApp "follow-link" (TTuple [TVar "V"])) env
          rewrite2 = do
            let env = emptyEnv
            env <- vsMatch fargs [VPMetaVar "V"] env
            env <- sideCondition (SCNotInSort (TVar "V") (TName "all-links")) env
            rewriteTermTo (TVar "V") env