Changeset 3565 for src/Pugs/Junc.hs

Show
Ignore:
Timestamp:
05/21/05 09:28:16 (4 years ago)
Author:
scook0
svk:copy_cache_prev:
5154
Message:

* Haddocks for 'juncApply' in Junc.hs
* Export-list nuking is now much more elegant (bsb++)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/Pugs/Junc.hs

    r3530 r3565  
    7777    = Nothing 
    7878 
    79 mergeJunc :: JuncType -> [Val] -> [Val] -> VJunc 
     79{-| 
     80Merge the contents of two @any@ or @one@ junctions into a single, combined  
     81junction value. 
     82 
     83For 'JAny', values are simply collapsed into @Set@s (duplicate values are 
     84discarded). 
     85 
     86For 'JOne', newly-created duplicates are extracted from the combined list of 
     87values and moved into the combined set of duplicates. 
     88-} 
     89mergeJunc :: JuncType -- ^ Type of the junctions being combined 
     90          -> [Val]    -- ^ Concatenated list of duplicates (only used for @one@) 
     91          -> [Val]    -- ^ Concatenated list of regular values 
     92          -> VJunc 
    8093mergeJunc j ds vs 
    8194    = case j of 
     
    91104-- Second pass - thread thru any() and one() 
    92105 
    93 juncApply :: ([ApplyArg] -> Eval Val) -> [ApplyArg] -> Eval Val 
     106{-| 
     107Core of the \"hideously clever\" autothreading algorithm. 
     108 
     109This function scans through the list of 'ApplyArg's, finds any that are 
     110uncollapsed junctions, and transposes the \'sub call with junction argument\' 
     111into \'junction of sub calls with non-junction arguments\'. It then recursively 
     112applies itself to each of those newly-created \'threads\', so ultimately all 
     113the call's arguments are properly collapsed. 
     114 
     115The scanning process will thread through @all@ and @none@ before it threads 
     116through @any@ and @one@. 
     117 
     118Once all the args /are/ collapsed, we call our first argument with the final, 
     119collapsed args. This happens once for each possible combination of (collapsed) 
     120arguments. 
     121 
     122Note that 'juncApply' takes place /after/ parameter binding (because it must), 
     123but /before/ we actually introduce any bindings into the sub's lexical scope. 
     124-} 
     125juncApply :: ([ApplyArg] -> Eval Val) -- ^ Function to call once we know the 
     126                                      --     collapsed arg values 
     127          -> [ApplyArg]               -- ^ List of arguments to autothread over 
     128          -> Eval Val 
    94129juncApply f args 
    95130    | this@(_, (pivot:_)) <- break isTotalJunc args 
     
    116151    appList _ _ = internalError "appList: list doesn't begin with ApplyArg" 
    117152 
     153{-| 
     154Return @True@ if the given 'ApplyArg' (autothreaded argument) represents a 
     155junction value that is @all@ or @none@, /and/ still needs to autothreaded. 
     156 
     157Other junctions, total junctions that don't need collapsing, and non-junction 
     158values will all produce @False@. 
     159-} 
    118160isTotalJunc :: ApplyArg -> Bool 
    119161isTotalJunc arg 
     
    124166    = False 
    125167 
     168{-| 
     169Return @True@ if the given 'ApplyArg' (autothreaded argument) represents a 
     170junction value that is @one@ or @any@, /and/ still needs to be autothreaded. 
     171 
     172Other junctions, partial junctions that don't need collapsing, and non-junction 
     173values will all produce @False@. 
     174-} 
    126175isPartialJunc :: ApplyArg -> Bool 
    127176isPartialJunc arg 
     
    132181    = False 
    133182 
     183{-| 
     184Represents a sub argument during the junction autothreading process. 
     185 
     186Note that 'argCollapsed' is set to @True@ only if the corresponding sub param 
     187is explicitly specified as being (Perl6) type @Junc@. 
     188-} 
    134189data ApplyArg = ApplyArg 
    135     { argName       :: String 
    136     , argValue      :: Val 
    137     , argCollapsed  :: Bool 
     190    { argName       :: String -- ^ Name of the param that this arg is for 
     191    , argValue      :: Val    -- ^ Actual argument value, which may still be 
     192                              --     a junction 
     193    , argCollapsed  :: Bool   -- ^ @True@ if we have confirmed that this arg 
     194                              --     doesn't need any further autothreading 
    138195    } 
    139196    deriving (Show, Eq, Ord)