source: sizechecking/branches/macs/Size.hs @ 26

Last change on this file since 26 was 25, checked in by gobi, 11 years ago

monad for observable sharing

File size: 1.4 KB
RevLine 
[25]1{-# LANGUAGE TypeFamilies #-}
2{-# LANGUAGE MultiParamTypeClasses #-}
3{-# LANGUAGE FlexibleInstances #-}
4
[22]5module Size where
6
7import Lambda
8import Ops
9import Data.Supply as S
10
11data Unsized
12
13class (LOps l) => Size l where
14    list :: l Int -> l (Int -> a) -> l [a]
15    slam :: (l Int -> l (Int -> a) -> l b) -> l ([a] -> b)
16    shift :: l (Int -> a) -> l Int -> l (Int -> a) -> l (Int -> a)
17    unsized :: l Unsized
18    bottom :: l a
19
[25]20
[22]21instance Size S where
22    unsized = S $ \_ _ -> showChar 'U'
23    bottom = S $ \_ _ -> showChar '┮'
24    list size sexp = S $ \s p ->
25        let (s1, s2) = S.split2 s
26        in showParen (p>0) $
27            showString "List " .
28            unS size s1 9 .
29            showChar ' ' .
30            unS sexp s2 9
31    slam f = S $ \s p ->
32        let (s1, s2, s3) = S.split3 s
33            v1           = S.supplyValue s1
34            showV1       = S $ \_ _ -> showVar v1
35            v2           = S.supplyValue s2
36            showV2       = S $ \_ _ -> showVar v2
37        in showParen (p>0) $
38            showChar 'Λ' .
39            showVar v1 .
40            showChar ',' .
41            showVar v2 .
42            showChar '.' .
43            unS (f showV1 showV2) s3 0
44    shift e1 ss e2 = S $ \s p ->
45        let (s1, s2, s3) = S.split3 s
46        in showParen (p>0)
47        $ showString "Shift "
48        . unS e1 s1 2
49        . showChar ' '
50        . unS ss s2 2
51        . showChar ' '
52        . unS e2 s3 2
[25]53
Note: See TracBrowser for help on using the repository browser.