Changeset 15407

Show
Ignore:
Timestamp:
03/02/07 11:34:17 (21 months ago)
Author:
gaal
Message:

* fixed-point golf: get "HOW" and "WHICH" methods on all pure

classes automatically.

Location:
src/Pugs
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Class.hs

    r15399 r15407  
    1919    , module MO.Compile.Class 
    2020    , module MO.Util 
     21    , module Control.Monad.Fix 
    2122    ) where 
    2223import MO.Run hiding (__) 
     
    2627import Pugs.Internals 
    2728import Pugs.AST.Eval 
     29import Control.Monad.Fix 
    2830 
    2931class (Show a, Typeable a, Ord a, Typeable1 m, Monad m) => Boxable m a | a -> m where 
     
    7375    } 
    7476 
     77mkBoxPureClass :: forall a1 (m :: * -> *) a (m1 :: * -> *). 
     78    ( Boxable m a1 
     79    , Boxable m a 
     80    , Codeable m1 (HsCode m) 
     81    , Typeable1 m1 
     82    ) => String -> [(ID, a1 -> m (Invocant m))] -> a -> MI m1 
     83mkBoxPureClass cls methods self = 
     84    mkBoxClass cls methods' 
     85    where 
     86        methods' = methods ++ 
     87            [ "HOW"         ... (const self) 
     88            , "WHICH"       ... id 
     89            ] 
     90 
    7591mkBoxMethod :: forall t (m1 :: * -> *) (m :: * -> *). 
    7692    ( Method m (SimpleMethod m) 
  • src/Pugs/Meta/Str.hs

    r15397 r15407  
    1010 
    1111_StrClass :: PureClass 
    12 _StrClass = mkBoxClass "Str" 
     12_StrClass = fix $ mkBoxPureClass "Str" 
    1313    [ "reverse"     ... (MkStr . Str.reverse . unStr) 
    14     , "HOW"         ... (const _StrClass) 
    15     , "WHICH"       ... id 
    1614    ] 
    1715