Changeset 15096 for src/Pugs/Val

Show
Ignore:
Timestamp:
01/19/07 17:41:44 (22 months ago)
Author:
audreyt
Message:

* Pugs.Val: Make ICoercible a superclass of Boxable, and

introduce PureStr? (Str in userland) as the first MO'ed class.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Val/Base.hs

    r13587 r15096  
    1 {-# OPTIONS_GHC -fglasgow-exts -fallow-overlapping-instances -funbox-strict-fields #-} 
     1{-# OPTIONS_GHC -fglasgow-exts -fallow-overlapping-instances -funbox-strict-fields -fallow-undecidable-instances #-} 
    22 
    33module Pugs.Val.Base where 
     
    66 
    77import Pugs.Internals 
     8import Pugs.Class 
    89import {-# SOURCE #-} Pugs.Val 
    910 
     
    3334    asNative :: a -> m ValNative 
    3435    asNative = fmap (NBuf . cast) . asStr 
     36    classOf :: a -> MI m 
     37    fromObj :: Invocant m -> m a 
    3538 
    3639type PureList       = Seq Val -- Seq (Either PureSeq PureRange) -- XXX - *very bogus* 
     
    107110-- PureStr 
    108111 
    109 newtype PureStr = MkStr ByteString deriving 
     112newtype PureStr = MkStr { unStr :: ByteString } deriving 
    110113    ( Typeable, Show, Eq, Ord, Data 
    111114    , (:>:) ID, (:<:) ID 
     
    117120parseInt (MkStr s) = maybe 0 fst (Char8.readInt s) 
    118121 
     122instance (Typeable1 m, Ord a, ICoercible m a) => Boxable m a where 
     123    fromObjBox = fromObj 
     124    classOfBox = classOf 
     125 
    119126instance ICoercible P PureStr where 
    120127    asBit (MkStr s) 
     
    124131    asNum = cast . parseInt -- XXX - wrong 
    125132    asInt = cast . parseInt 
     133    fromObj (MkInvocant x _) = undefined 
     134    classOf _ = mkBoxClass "Str" 
     135        [ "reverse"    ... (MkStr . Char8.reverse . unStr) 
     136        ] 
    126137