Changeset 3565 for src/Pugs/Junc.hs
- Timestamp:
- 05/21/05 09:28:16 (4 years ago)
- svk:copy_cache_prev:
- 5154
- Files:
-
- 1 modified
-
src/Pugs/Junc.hs (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
src/Pugs/Junc.hs
r3530 r3565 77 77 = Nothing 78 78 79 mergeJunc :: JuncType -> [Val] -> [Val] -> VJunc 79 {-| 80 Merge the contents of two @any@ or @one@ junctions into a single, combined 81 junction value. 82 83 For 'JAny', values are simply collapsed into @Set@s (duplicate values are 84 discarded). 85 86 For 'JOne', newly-created duplicates are extracted from the combined list of 87 values and moved into the combined set of duplicates. 88 -} 89 mergeJunc :: 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 80 93 mergeJunc j ds vs 81 94 = case j of … … 91 104 -- Second pass - thread thru any() and one() 92 105 93 juncApply :: ([ApplyArg] -> Eval Val) -> [ApplyArg] -> Eval Val 106 {-| 107 Core of the \"hideously clever\" autothreading algorithm. 108 109 This function scans through the list of 'ApplyArg's, finds any that are 110 uncollapsed junctions, and transposes the \'sub call with junction argument\' 111 into \'junction of sub calls with non-junction arguments\'. It then recursively 112 applies itself to each of those newly-created \'threads\', so ultimately all 113 the call's arguments are properly collapsed. 114 115 The scanning process will thread through @all@ and @none@ before it threads 116 through @any@ and @one@. 117 118 Once all the args /are/ collapsed, we call our first argument with the final, 119 collapsed args. This happens once for each possible combination of (collapsed) 120 arguments. 121 122 Note that 'juncApply' takes place /after/ parameter binding (because it must), 123 but /before/ we actually introduce any bindings into the sub's lexical scope. 124 -} 125 juncApply :: ([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 94 129 juncApply f args 95 130 | this@(_, (pivot:_)) <- break isTotalJunc args … … 116 151 appList _ _ = internalError "appList: list doesn't begin with ApplyArg" 117 152 153 {-| 154 Return @True@ if the given 'ApplyArg' (autothreaded argument) represents a 155 junction value that is @all@ or @none@, /and/ still needs to autothreaded. 156 157 Other junctions, total junctions that don't need collapsing, and non-junction 158 values will all produce @False@. 159 -} 118 160 isTotalJunc :: ApplyArg -> Bool 119 161 isTotalJunc arg … … 124 166 = False 125 167 168 {-| 169 Return @True@ if the given 'ApplyArg' (autothreaded argument) represents a 170 junction value that is @one@ or @any@, /and/ still needs to be autothreaded. 171 172 Other junctions, partial junctions that don't need collapsing, and non-junction 173 values will all produce @False@. 174 -} 126 175 isPartialJunc :: ApplyArg -> Bool 127 176 isPartialJunc arg … … 132 181 = False 133 182 183 {-| 184 Represents a sub argument during the junction autothreading process. 185 186 Note that 'argCollapsed' is set to @True@ only if the corresponding sub param 187 is explicitly specified as being (Perl6) type @Junc@. 188 -} 134 189 data 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 138 195 } 139 196 deriving (Show, Eq, Ord)
