Changeset 25 for sizechecking/branches
- Timestamp:
- May 4, 2014, 6:57:47 PM (11 years ago)
- Location:
- sizechecking/branches/macs
- Files:
-
- 2 added
- 3 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
sizechecking/branches/macs/Lambda.hs
r24 r25 1 {-# LANGUAGE FlexibleContexts,FlexibleInstances #-} 1 {-# LANGUAGE TypeFamilies #-} 2 2 3 module Lambda where 3 4 4 5 import qualified Data.Supply as S 5 6 import qualified Data.Char as C 7 import Control.Monad.IO.Class (MonadIO, liftIO) 8 import Data.IORef (newIORef, readIORef, writeIORef) 6 9 7 10 {- … … 9 12 -} 10 13 class Lambda l where 11 lam 12 app 14 lam :: (l a -> l b) -> l (a -> b) 15 app :: l (a -> b) -> l a -> l b 13 16 lit :: Int -> l Int 14 17 … … 54 57 printAst :: S a -> IO () 55 58 printAst l = ast l >>= (\s -> putStrLn $ s "") 59 60 61 type family Sem (m :: * -> *) a :: * 62 type instance Sem m Int = Int 63 type instance Sem m (a -> b) = m (Sem m a) -> m (Sem m b) 64 65 newtype R m a = R { unR :: m (Sem m a) } 66 67 share :: (MonadIO m) => m a -> m (m a) 68 share f = do 69 mem <- liftIO $ newIORef (False, f) 70 return $ do 71 (evald, thunk) <- liftIO $ readIORef mem 72 if evald then thunk 73 else do 74 value <- thunk 75 liftIO $ writeIORef mem (True, return value) 76 return value 77 78 instance (MonadIO m) => Lambda (R m) where 79 app x y = R $ unR x >>= ($ (unR y)) 80 lit = R . return 81 lam f = R . return $ (\x -> share x >>= unR . f . R) -
sizechecking/branches/macs/Ops.hs
r23 r25 1 {-# LANGUAGE FlexibleInstances #-}1 {-# LANGUAGE FlexibleInstances, KindSignatures #-} 2 2 3 3 module Ops where … … 8 8 import Lambda 9 9 10 -- infix operatorok, ezek beagyazasa picit necces, lasd a type family kesobb 10 11 class (Lambda l) => LOps l where 11 infixop :: String -> Int -> (a -> b -> c) -> l a -> l b -> l c12 infixop :: String -> Int -> (a -> b -> c) -> l a -> l b -> l c 12 13 infixopr :: String -> Int -> (a -> b -> c) -> l a -> l b -> l c 13 14 infixopl :: String -> Int -> (a -> b -> c) -> l a -> l b -> l c 14 fun :: String -> a -> l a15 fun :: String -> a -> l a 15 16 16 (+) ::l Int -> l Int -> l Int17 17 (+) :: (LOps l) => l Int -> l Int -> l Int 18 (+) = infixopl "+" 6 (Prelude.+) 18 19 19 (-) ::l Int -> l Int -> l Int20 20 (-) :: (LOps l) => l Int -> l Int -> l Int 21 (-) = infixopl "-" 6 (Prelude.-) 21 22 22 (*) :: l Int -> l Int -> l Int 23 (*) = infixopl "*" 7 (Prelude.*) 23 (*) :: (LOps l) => l Int -> l Int -> l Int 24 (*) = infixopl "*" 7 (Prelude.*) 25 24 26 25 27 -
sizechecking/branches/macs/Size.hs
r22 r25 1 {-# LANGUAGE TypeFamilies #-} 2 {-# LANGUAGE MultiParamTypeClasses #-} 3 {-# LANGUAGE FlexibleInstances #-} 4 1 5 module Size where 2 6 … … 13 17 unsized :: l Unsized 14 18 bottom :: l a 19 15 20 16 21 instance Size S where … … 46 51 . showChar ' ' 47 52 . unS e2 s3 2 53
Note: See TracChangeset
for help on using the changeset viewer.