diff options
author | tomsmeding <tom.smeding@gmail.com> | 2017-01-24 21:16:42 +0100 |
---|---|---|
committer | tomsmeding <tom.smeding@gmail.com> | 2017-01-24 21:16:42 +0100 |
commit | f9f666c7088ad2acde6dad3bd57ebf8438ba9ea1 (patch) | |
tree | 696a21da32121ec82a2d7bfa5b643f82ff285b30 /namegen | |
parent | 68a49640d7cf05c3149da266e820c5ce464aadf8 (diff) |
Can codegen a simple variable declaration
Diffstat (limited to 'namegen')
-rw-r--r-- | namegen/test.hs | 47 |
1 files changed, 0 insertions, 47 deletions
diff --git a/namegen/test.hs b/namegen/test.hs deleted file mode 100644 index caa7111..0000000 --- a/namegen/test.hs +++ /dev/null @@ -1,47 +0,0 @@ -type Index = Integer - -data Namegen a = Namegen (Index -> (a, Index)) - -runNameGen :: Index -> Namegen a -> a -runNameGen i (Namegen f) = fst (f i) - -supply :: Namegen Integer -supply = Namegen $ \i -> (i, i + 1) - -makeName :: String -> Namegen String -makeName base = supply >>= \i -> return $ base ++ show i - -makeTempName :: Namegen String -makeTempName = makeName "t" - -instance Functor Namegen where - fmap f (Namegen g) = Namegen $ \i -> let (x, i2) = g i in (f x, i2) - -instance Applicative Namegen where - pure x = Namegen $ \i -> (x, i) - - (Namegen fg) <*> (Namegen xg) = - Namegen $ \i -> let (f, i2) = fg i - (x, i3) = xg i2 - in (f x, i3) - -instance Monad Namegen where - (Namegen xg) >>= f = - Namegen $ \i -> let (x, i2) = xg i - (Namegen resg) = f x - in resg i2 - - -funString :: Int -> Namegen String -funString i = do - n1 <- makeTempName - n2 <- makeTempName - return $ "Fun String " ++ show i ++ ", made with '" ++ n1 ++ "' and '" ++ n2 ++ "'" - -main :: IO () -main = do - putStrLn $ runNameGen 1 $ do - n1 <- makeName "xyz" - s <- funString 42 - n2 <- makeName "abc" - return $ s ++ "\nGenerated names " ++ n1 ++ " and " ++ n2 |