source: sizechecking/branches/macs/Ops.hs

Last change on this file was 27, checked in by gobi, 11 years ago

new files

File size: 2.0 KB
RevLine 
[25]1{-# LANGUAGE FlexibleInstances, KindSignatures #-}
[21]2
[20]3module Ops where
4
[21]5import qualified Data.Supply as S
6import Prelude (String, Int, ($), (.))
7import qualified Prelude
[20]8import Lambda
[27]9import Data.Lens.Light
[21]10
[25]11-- infix operatorok, ezek beagyazasa picit necces, lasd a type family kesobb
[21]12class (Lambda l) => LOps l where
[25]13    infixop  :: String -> Int -> (a -> b -> c) -> l a -> l b -> l c
[23]14    infixopr :: String -> Int -> (a -> b -> c) -> l a -> l b -> l c
15    infixopl :: String -> Int -> (a -> b -> c) -> l a -> l b -> l c
[25]16    fun ::  String -> a -> l a
[21]17
[25]18(+) :: (LOps l) => l Int -> l Int -> l Int
19(+) = infixopl "+" 6 (Prelude.+)
[21]20
[25]21(-) :: (LOps l) => l Int -> l Int -> l Int
22(-) = infixopl "-" 6 (Prelude.-)
[21]23
[25]24(*) :: (LOps l) => l Int -> l Int -> l Int
25(*) = infixopl "*" 7 (Prelude.*)
[21]26
27
[25]28
[21]29instance LOps Q where
[23]30    infixopl _ _ f lhs rhs = Q (eval lhs `f` eval rhs)
31    infixop  _ _ f lhs rhs = Q (eval lhs `f` eval rhs)
32    infixopr _ _ f lhs rhs = Q (eval lhs `f` eval rhs)
[21]33    fun _ = Q
34
[27]35instance (SContext s) => LOps (S s) where
36    fun name _ = S (\ctx -> Prelude.showsPrec (getL prec ctx) name)
[21]37
[27]38    infixopl name p _ lhs rhs = S(\ctx ->
39        let (s1, s2) = S.split2 (getL supply ctx)
40        in Prelude.showParen ((getL prec ctx) Prelude.> p) $
41            unS lhs (setL supply s1 $ setL prec p ctx) .
[21]42            Prelude.showString name .
[27]43            unS rhs (setL supply s2 $ setL prec (Prelude.succ p) ctx)
[21]44        )
[27]45
46    infixop  name p _ lhs rhs = S(\ctx ->
47        let (s1, s2) = S.split2 (getL supply ctx)
48        in Prelude.showParen ((getL prec ctx) Prelude.> p) $
49            unS lhs (setL supply s1 $ setL prec (Prelude.succ p) ctx) .
[23]50            Prelude.showString name .
[27]51            unS rhs (setL supply s2 $ setL prec (Prelude.succ p) ctx)
[23]52        )
[27]53
54    infixopr name p _ lhs rhs = S(\ctx ->
55        let (s1, s2) = S.split2 (getL supply ctx)
56        in Prelude.showParen ((getL prec ctx) Prelude.> p) $
57            unS lhs (setL supply s1 $ setL prec (Prelude.succ p) ctx) .
[23]58            Prelude.showString name .
[27]59            unS rhs (setL supply s2 $ setL prec p ctx)
[23]60        )
Note: See TracBrowser for help on using the repository browser.