root/src/Pugs/Prim/Lifts.hs

Revision 4350, 1.4 kB (checked in by autrijus, 3 years ago)

* Fix ~{1=>2} to stringify to "1\t2\n" correctly.

Reported by broquaint.

  • Property svn:mime-type set to text/plain; charset=UTF-8
  • Property svn:eol-style set to native
Line 
1{-# OPTIONS_GHC -fglasgow-exts -fno-warn-orphans #-}
2
3module Pugs.Prim.Lifts (
4  op1Cast, op2Cast,
5  op2Array,
6  vCastStr, vCastRat,
7  op2Str, op2Num, op2Bool, op2Int, op2Rat,
8) where
9import Pugs.AST
10import Pugs.Types
11
12op1Cast :: (Value n) => (n -> Val) -> Val -> Eval Val
13op1Cast f val = fmap f (fromVal val)
14
15op2Cast :: (Value n, Value m) => (n -> m -> Val) -> Val -> Val -> Eval Val
16op2Cast f x y = do
17    x' <- fromVal =<< fromVal' x
18    y' <- fromVal =<< fromVal' y
19    return (f x' y')
20
21op2Array :: (forall a. ArrayClass a => a -> [Val] -> Eval ()) -> Val -> Val -> Eval Val
22op2Array f x y = do
23    f    <- doArray x f
24    vals <- fromVal y
25    f vals
26    size <- doArray x array_fetchSize
27    idx  <- size
28    return $ castV idx
29
30vCastStr :: Val -> Eval VStr
31vCastStr = fromVal
32vCastRat :: Val -> Eval VRat
33vCastRat = fromVal
34
35op2Str :: (Value v1, Value v2) => (v1 -> v2 -> VStr) -> Val -> Val -> Eval Val
36op2Str f x y = do
37    x' <- fromVal x
38    y' <- fromVal y
39    return $ VStr $ f x' y'
40
41op2Num    :: (Value v1, Value v2) => (v1 -> v2 -> VNum) -> Val -> Val -> Eval Val
42op2Num  f = op2Cast $ (VNum .) . f
43
44op2Bool   :: (Value v1, Value v2) => (v1 -> v2 -> VBool) -> Val -> Val -> Eval Val
45op2Bool f = op2Cast $ (VBool .) . f
46
47op2Int    :: (Value v1, Value v2) => (v1 -> v2 -> VInt) -> Val -> Val -> Eval Val
48op2Int  f = op2Cast $ (VInt .) . f
49
50op2Rat    :: (Value v1, Value v2) => (v1 -> v2 -> VRat) -> Val -> Val -> Eval Val
51op2Rat  f = op2Cast $ (VRat .) . f
Note: See TracBrowser for help on using the browser.