Changeset 26 for sizechecking/branches/macs/Lambda.hs
- Timestamp:
- May 4, 2014, 8:06:39 PM (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sizechecking/branches/macs/Lambda.hs
r25 r26 1 {-# LANGUAGE TypeFamilies #-}1 {-# LANGUAGE TypeFamilies, GADTs #-} 2 2 3 3 module Lambda where … … 36 36 else showChar $ C.chr $ C.ord 'a' + x 37 37 38 -- unS :: Value supply -> Precedence -> ShowS39 38 newtype S a = S { unS :: S.Supply Int -> Int -> ShowS } 40 39 … … 59 58 60 59 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) 60 {- 61 - reduction 62 -} 63 data IR h t where 64 Lit :: Int -> IR h Int 65 App :: IR h (a -> b) -> IR h a -> IR h b 66 Lam :: (IR h a -> IR h b) -> IR h (a -> b) 64 67 65 newtype R m a = R { unR :: m (Sem m a) } 68 instance Lambda (IR h) where 69 lam = Lam 70 app = App 71 lit = Lit 66 72 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) 73 toFinal :: (Lambda l) => IR h t
Note: See TracChangeset
for help on using the changeset viewer.