From 88d77a9843bfb15055b2226b4ee1354c2f3a0010 Mon Sep 17 00:00:00 2001 From: Rob Rix Date: Tue, 11 Dec 2018 15:50:46 -0500 Subject: [PATCH] Define a String effect. Co-Authored-By: Ayman Nadeem --- src/Control/Abstract/Value.hs | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/Control/Abstract/Value.hs b/src/Control/Abstract/Value.hs index 98ca0dfd6..c381b7ad7 100644 --- a/src/Control/Abstract/Value.hs +++ b/src/Control/Abstract/Value.hs @@ -28,6 +28,7 @@ module Control.Abstract.Value , Unit(..) , runUnit , UnitC(..) +, String(..) ) where import Control.Abstract.Evaluator @@ -40,6 +41,7 @@ import Data.Abstract.Name import Data.Abstract.Number as Number import Data.Scientific (Scientific) import Data.Span +import Prelude hiding (String) import Prologue hiding (TypeError) -- | This datum is passed into liftComparison to handle the fact that Ruby and PHP @@ -212,6 +214,19 @@ runUnit :: Carrier (Unit value :+: sig) (UnitC value (Eff m)) -> Evaluator term address value m a runUnit = raiseHandler $ runUnitC . interpret +data String value (m :: * -> *) k + = String Text (value -> k) + | AsString value (Text -> k) + deriving (Functor) + +instance HFunctor (String value) where + hmap _ = coerce + {-# INLINE hmap #-} + +instance Effect (String value) where + handle state handler (String text k) = String text (handler . (<$ state) . k) + handle state handler (AsString v k) = AsString v (handler . (<$ state) . k) + class Show value => AbstractIntro value where -- | Construct an abstract string value.