Changeset 15439

Show
Ignore:
Timestamp:
03/04/07 14:40:43 (21 months ago)
Author:
audreyt
Message:

* Pugs.Class: Allow the right hand side of ./ to be polymorphic,

thus allowing two convenient callconv forms (more to come):

obj ./ meth
obj ./ (meth, pos, nam)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Class.hs

    r15425 r15439  
    1 {-# OPTIONS_GHC -fglasgow-exts -cpp #-} 
     1{-# OPTIONS_GHC -fglasgow-exts -fparr #-} 
    22 
    33{-| 
     
    2424import MO.Compile 
    2525import MO.Compile.Class 
    26 import MO.Util 
     26import MO.Util hiding (traceM, traceShow) 
    2727import Pugs.Internals 
    2828import Pugs.AST.Eval 
    2929import Control.Monad.Fix 
     30import qualified Data.Map as Map 
     31import qualified Data.Typeable as Typeable 
    3032 
    3133class (Show a, Typeable a, Ord a, Typeable1 m, Monad m) => Boxable m a | a -> m where 
     
    4446 
    4547    fromObj :: Invocant m -> m a 
    46     fromObj (MkInvocant x _) = fromTypeable x 
     48    fromObj (MkInvocant x _) = case Typeable.cast x of 
     49        Just y -> return y 
     50        _      -> fail $ "Cannot coerce from " ++ (show $ typeOf x) ++ " to " ++ (show $ typeOf (undefined :: a)) 
    4751 
    4852(...) :: Boxable m b => String -> (a -> b) -> (ID, a -> m (Invocant m)) 
     
    110114    } 
    111115 
    112 (./) :: (Typeable1 m, Monad m) => Invocant m -> ID -> m (Invocant m) 
    113 inv ./ meth = ivDispatch inv $ MkMethodInvocation meth (mkArgs []) 
     116(./) :: ((:>:) (MethodInvocation Eval) a) => Invocant Eval -> a -> Eval (Invocant Eval) 
     117x ./ y = ivDispatch x (cast y) 
    114118 
    115119type PureClass = MI Eval 
     
    126130    ] 
    127131 
     132instance ((:>:) (MethodInvocation Eval)) ByteString where 
     133    cast = (`MkMethodInvocation` CaptSub{ c_feeds = [::] }) . cast 
     134 
     135instance ((:>:) (MethodInvocation Eval) (ByteString, [Invocant Eval], Map ID (Invocant Eval))) where 
     136    cast (meth, pos, named) = MkMethodInvocation (cast meth) CaptSub{ c_feeds = [: MkFeed (toP pos) (Map.map (\x -> [:x:]) named) :]} 
     137