2 % (c) The AQUA Project, Glasgow University, 1996-98
4 \section[CmdLineOpts]{Things to do with command-line options}
18 opt_AllowOverlappingInstances,
19 opt_AllowUndecidableInstances,
20 opt_AutoSccsOnAllToplevs,
21 opt_AutoSccsOnExportedToplevs,
22 opt_AutoSccsOnIndividualCafs,
30 opt_D_dump_occur_anal,
35 opt_D_dump_simpl_iterations,
42 opt_D_show_rn_imports,
43 opt_D_simplifier_stats,
45 opt_D_verbose_core2core,
46 opt_D_verbose_stg2stg,
54 opt_EnsureSplittableC,
60 opt_IgnoreIfacePragmas,
61 opt_IrrefutableTuples,
62 opt_LiberateCaseThreshold,
63 opt_MaxContextReductionDepth,
64 opt_MultiParamClasses,
66 opt_NoImplicitPrelude,
70 opt_OmitInterfacePragmas,
77 opt_ProduceExportCStubs,
78 opt_ProduceExportHStubs,
84 opt_StgDoLetNoEscapes,
87 opt_InterfaceUnfoldThreshold,
89 opt_UnfoldingCreationThreshold,
90 opt_UnfoldingConDiscount,
91 opt_UnfoldingUseThreshold,
92 opt_UnfoldingKeenessFactor,
96 opt_WarnNameShadowing,
97 opt_WarnUnusedMatches,
99 opt_WarnUnusedImports,
100 opt_WarnIncompletePatterns,
101 opt_WarnOverlappingPatterns,
102 opt_WarnSimplePatterns,
103 opt_WarnTypeDefaults,
104 opt_WarnMissingMethods,
105 opt_WarnDuplicateExports,
108 opt_PruneTyDecls, opt_PruneInstDecls,
112 #include "HsVersions.h"
114 import Array ( array, (//) )
117 import Constants -- Default values for some flags
119 import Maybes ( assocMaybe, firstJust, maybeToBool )
120 import Panic ( panic, panic# )
122 #if __GLASGOW_HASKELL__ < 301
123 import ArrBase ( Array(..) )
125 import PrelArr ( Array(..) )
129 A command-line {\em switch} is (generally) either on or off; e.g., the
130 ``verbose'' (-v) switch is either on or off. (The \tr{-G<group>}
131 switch is an exception; it's set to a string, or nothing.)
133 A list of {\em ToDo}s is things to be done in a particular part of
134 processing. A (fictitious) example for the Core-to-Core simplifier
135 might be: run the simplifier, then run the strictness analyser, then
136 run the simplifier again (three ``todos'').
138 There are three ``to-do processing centers'' at the moment. In the
139 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
140 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
141 (\tr{simplStg/SimplStg.lhs}).
143 %************************************************************************
145 \subsection{Datatypes associated with command-line options}
147 %************************************************************************
151 = SwBool Bool -- on/off
152 | SwString FAST_STRING -- nothing or a String
153 | SwInt Int -- nothing or an Int
157 data CoreToDo -- These are diff core-to-core passes,
158 -- which may be invoked in any order,
159 -- as many times as you like.
161 = CoreDoSimplify -- The core-to-core simplifier.
162 (SimplifierSwitch -> SwitchResult)
163 -- Each run of the simplifier can take a different
164 -- set of simplifier-specific flags.
165 | CoreDoCalcInlinings1
166 | CoreDoCalcInlinings2
174 | CoreDoFoldrBuildWorkerWrapper
175 | CoreDoFoldrBuildWWAnal
181 | StgDoUpdateAnalysis
183 | StgDoMassageForProfiling -- should be (next to) last
184 -- There's also setStgVarInfo, but its absolute "lastness"
185 -- is so critical that it is hardwired in (no flag).
190 data SimplifierSwitch
192 | SimplFloatLetsExposingWHNF
193 | SimplOkToFloatPrimOps
194 | SimplAlwaysFloatLetsFromLets
198 | SimplMayDeleteConjurableIds
199 | SimplPedanticBottoms -- see Simplifier for an explanation
200 | SimplDoArityExpand -- expand arity of bindings
201 | SimplDoFoldrBuild -- This is the per-simplification flag;
202 -- see also FoldrBuildOn, used elsewhere
204 | SimplDoInlineFoldrBuild
205 -- inline foldr/build (*after* f/b rule is used)
208 | SimplDoLambdaEtaExpansion
210 | EssentialUnfoldingsOnly -- never mind the thresholds, only
211 -- do unfoldings that *must* be done
212 -- (to saturate constructors and primitives)
214 | MaxSimplifierIterations Int
216 | SimplNoLetFromCase -- used when turning off floating entirely
217 | SimplNoLetFromApp -- (for experimentation only) WDP 95/10
218 | SimplNoLetFromStrictLet
224 %************************************************************************
226 \subsection{Classifying command-line options}
228 %************************************************************************
231 lookUp :: FAST_STRING -> Bool
232 lookup_int :: String -> Maybe Int
233 lookup_def_int :: String -> Int -> Int
234 lookup_def_float :: String -> Float -> Float
235 lookup_str :: String -> Maybe String
237 lookUp sw = maybeToBool (assoc_opts sw)
239 lookup_str sw = firstJust (map (startsWith sw) unpacked_opts)
241 lookup_int sw = case (lookup_str sw) of
243 Just xx -> Just (read xx)
245 lookup_def_int sw def = case (lookup_str sw) of
246 Nothing -> def -- Use default
249 lookup_def_float sw def = case (lookup_str sw) of
250 Nothing -> def -- Use default
253 assoc_opts = assocMaybe [ (a, True) | a <- argv ]
254 unpacked_opts = map _UNPK_ argv
257 Putting the compiler options into temporary at-files
258 may turn out to be necessary later on if we turn hsc into
259 a pure Win32 application where I think there's a command-line
260 length limit of 255. unpacked_opts understands the @ option.
262 assoc_opts = assocMaybe [ (_PK_ a, True) | a <- unpacked_opts ]
264 unpacked_opts :: [String]
270 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
276 opt_AllStrict = lookUp SLIT("-fall-strict")
277 opt_AllowOverlappingInstances = lookUp SLIT("-fallow-overlapping-instances")
278 opt_AllowUndecidableInstances = lookUp SLIT("-fallow-undecidable-instances")
279 opt_AutoSccsOnAllToplevs = lookUp SLIT("-fauto-sccs-on-all-toplevs")
280 opt_AutoSccsOnExportedToplevs = lookUp SLIT("-fauto-sccs-on-exported-toplevs")
281 opt_AutoSccsOnIndividualCafs = lookUp SLIT("-fauto-sccs-on-individual-cafs")
282 opt_D_dump_absC = lookUp SLIT("-ddump-absC")
283 opt_D_dump_asm = lookUp SLIT("-ddump-asm")
284 opt_D_dump_deriv = lookUp SLIT("-ddump-deriv")
285 opt_D_dump_ds = lookUp SLIT("-ddump-ds")
286 opt_D_dump_flatC = lookUp SLIT("-ddump-flatC")
287 opt_D_dump_inlinings = lookUp SLIT("-ddump-inlinings")
288 opt_D_dump_foreign = lookUp SLIT("-ddump-foreign-stubs")
289 opt_D_dump_occur_anal = lookUp SLIT("-ddump-occur-anal")
290 opt_D_dump_rdr = lookUp SLIT("-ddump-rdr")
291 opt_D_dump_realC = lookUp SLIT("-ddump-realC")
292 opt_D_dump_rn = lookUp SLIT("-ddump-rn")
293 opt_D_dump_simpl = lookUp SLIT("-ddump-simpl")
294 opt_D_dump_simpl_iterations = lookUp SLIT("-ddump-simpl-iterations")
295 opt_D_dump_spec = lookUp SLIT("-ddump-spec")
296 opt_D_dump_stg = lookUp SLIT("-ddump-stg")
297 opt_D_dump_stranal = lookUp SLIT("-ddump-stranal")
298 opt_D_dump_tc = lookUp SLIT("-ddump-tc")
299 opt_D_show_passes = lookUp SLIT("-dshow-passes")
300 opt_D_show_rn_trace = lookUp SLIT("-dshow-rn-trace")
301 opt_D_show_rn_imports = lookUp SLIT("-dshow-rn-imports")
302 opt_D_simplifier_stats = lookUp SLIT("-dsimplifier-stats")
303 opt_D_source_stats = lookUp SLIT("-dsource-stats")
304 opt_D_verbose_core2core = lookUp SLIT("-dverbose-simpl")
305 opt_D_verbose_stg2stg = lookUp SLIT("-dverbose-stg")
306 opt_DictsStrict = lookUp SLIT("-fdicts-strict")
307 opt_DoCoreLinting = lookUp SLIT("-dcore-lint")
308 opt_DoStgLinting = lookUp SLIT("-dstg-lint")
309 opt_DoEtaReduction = lookUp SLIT("-fdo-eta-reduction")
310 opt_DoSemiTagging = lookUp SLIT("-fsemi-tagging")
311 opt_DoTickyProfiling = lookUp SLIT("-fticky-ticky")
312 opt_EmitCExternDecls = lookUp SLIT("-femit-extern-decls")
313 opt_EnsureSplittableC = lookUp SLIT("-fglobalise-toplev-names")
314 opt_FoldrBuildOn = lookUp SLIT("-ffoldr-build-on")
315 opt_GranMacros = lookUp SLIT("-fgransim")
316 opt_GlasgowExts = lookUp SLIT("-fglasgow-exts")
317 opt_HiMap = lookup_str "-himap=" -- file saying where to look for .hi files
318 opt_HiVersion = lookup_def_int "-fhi-version=" 0 -- what version we're compiling.
319 opt_IgnoreIfacePragmas = lookUp SLIT("-fignore-interface-pragmas")
320 opt_IrrefutableTuples = lookUp SLIT("-firrefutable-tuples")
321 opt_MaxContextReductionDepth = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
322 opt_MultiParamClasses = opt_GlasgowExts
323 opt_NoHiCheck = lookUp SLIT("-fno-hi-version-check")
324 opt_NoImplicitPrelude = lookUp SLIT("-fno-implicit-prelude")
325 opt_NoPreInlining = lookUp SLIT("-fno-pre-inlining")
326 opt_NumbersStrict = lookUp SLIT("-fnumbers-strict")
327 opt_OmitBlackHoling = lookUp SLIT("-dno-black-holing")
328 opt_OmitInterfacePragmas = lookUp SLIT("-fomit-interface-pragmas")
329 opt_PprStyle_NoPrags = lookUp SLIT("-dppr-noprags")
330 opt_PprStyle_Debug = lookUp SLIT("-dppr-debug")
331 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
332 opt_ProduceC = lookup_str "-C="
333 opt_ProduceS = lookup_str "-S="
334 opt_ProduceExportCStubs = lookup_str "-F="
335 opt_ProduceExportHStubs = lookup_str "-FH="
336 opt_ProduceHi = lookup_str "-hifile=" -- the one to produce this time
337 opt_ReportCompile = lookUp SLIT("-freport-compile")
338 opt_SccProfilingOn = lookUp SLIT("-fscc-profiling")
339 opt_SourceUnchanged = lookUp SLIT("-fsource-unchanged")
340 opt_StgDoLetNoEscapes = lookUp SLIT("-flet-no-escape")
341 opt_Parallel = lookUp SLIT("-fparallel")
342 opt_Static = lookUp SLIT("-static")
343 opt_SccGroup = lookup_str "-G="
344 opt_Verbose = lookUp SLIT("-v")
346 opt_UnfoldCasms = lookUp SLIT("-funfold-casms-in-hi-file")
347 opt_InterfaceUnfoldThreshold = lookup_def_int "-funfolding-interface-threshold" iNTERFACE_UNFOLD_THRESHOLD
348 opt_UnfoldingCreationThreshold = lookup_def_int "-funfolding-creation-threshold" uNFOLDING_CREATION_THRESHOLD
349 opt_UnfoldingUseThreshold = lookup_def_int "-funfolding-use-threshold" uNFOLDING_USE_THRESHOLD
350 opt_UnfoldingConDiscount = lookup_def_int "-funfolding-con-discount" uNFOLDING_CON_DISCOUNT_WEIGHT
352 opt_LiberateCaseThreshold = lookup_def_int "-fliberate-case-threshold" lIBERATE_CASE_THRESHOLD
353 opt_UnfoldingKeenessFactor = lookup_def_float "-funfolding-keeness-factor" uNFOLDING_KEENESS_FACTOR
354 opt_WarnNameShadowing = lookUp SLIT("-fwarn-name-shadowing")
355 opt_WarnHiShadows = lookUp SLIT("-fwarn-hi-shadowing")
356 opt_WarnIncompletePatterns = lookUp SLIT("-fwarn-incomplete-patterns")
357 opt_WarnOverlappingPatterns = lookUp SLIT("-fwarn-overlapping-patterns")
358 opt_WarnSimplePatterns = lookUp SLIT("-fwarn-simple-patterns")
359 opt_WarnTypeDefaults = lookUp SLIT("-fwarn-type-defaults")
360 opt_WarnUnusedMatches = lookUp SLIT("-fwarn-unused-matches")
361 opt_WarnUnusedBinds = lookUp SLIT("-fwarn-unused-binds")
362 opt_WarnUnusedImports = lookUp SLIT("-fwarn-unused-imports")
363 opt_WarnMissingMethods = lookUp SLIT("-fwarn-missing-methods")
364 opt_WarnDuplicateExports = lookUp SLIT("-fwarn-duplicate-exports")
365 opt_WarnMissingSigs = lookUp SLIT("-fwarn-missing-signatures")
366 opt_PruneTyDecls = not (lookUp SLIT("-fno-prune-tydecls"))
367 opt_PruneInstDecls = not (lookUp SLIT("-fno-prune-instdecls"))
368 opt_D_show_rn_stats = lookUp SLIT("-dshow-rn-stats")
370 -- opt_UnfoldingOverrideThreshold = lookup_int "-funfolding-override-threshold"
374 classifyOpts :: ([CoreToDo], -- Core-to-Core processing spec
375 [StgToDo]) -- STG-to-STG processing spec
377 classifyOpts = sep argv [] [] -- accumulators...
379 sep :: [FAST_STRING] -- cmd-line opts (input)
380 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
381 -> ([CoreToDo], [StgToDo]) -- result
383 sep [] core_td stg_td -- all done!
384 = (reverse core_td, reverse stg_td)
386 # define CORE_TD(to_do) sep opts (to_do:core_td) stg_td
387 # define STG_TD(to_do) sep opts core_td (to_do:stg_td)
389 sep (opt1:opts) core_td stg_td
390 = case (_UNPK_ opt1) of -- the non-"just match a string" options are at the end...
391 ',' : _ -> sep opts core_td stg_td -- it is for the parser
393 "-fsimplify" -> -- gather up SimplifierSwitches specially...
394 simpl_sep opts defaultSimplSwitches core_td stg_td
396 "-fcalc-inlinings1"-> CORE_TD(CoreDoCalcInlinings1)
397 "-fcalc-inlinings2"-> CORE_TD(CoreDoCalcInlinings2)
398 "-ffloat-inwards" -> CORE_TD(CoreDoFloatInwards)
399 "-ffull-laziness" -> CORE_TD(CoreDoFullLaziness)
400 "-fliberate-case" -> CORE_TD(CoreLiberateCase)
401 "-fprint-core" -> CORE_TD(CoreDoPrintCore)
402 "-fstatic-args" -> CORE_TD(CoreDoStaticArgs)
403 "-fstrictness" -> CORE_TD(CoreDoStrictness)
404 "-fspecialise" -> CORE_TD(CoreDoSpecialising)
405 "-ffoldr-build-worker-wrapper" -> CORE_TD(CoreDoFoldrBuildWorkerWrapper)
406 "-ffoldr-build-ww-anal" -> CORE_TD(CoreDoFoldrBuildWWAnal)
408 "-fstg-static-args" -> STG_TD(StgDoStaticArgs)
409 "-fupdate-analysis" -> STG_TD(StgDoUpdateAnalysis)
410 "-dstg-stats" -> STG_TD(D_stg_stats)
411 "-flambda-lift" -> STG_TD(StgDoLambdaLift)
412 "-fmassage-stg-for-profiling" -> STG_TD(StgDoMassageForProfiling)
414 _ -> -- NB: the driver is really supposed to handle bad options
415 sep opts core_td stg_td
419 simpl_sep :: [FAST_STRING] -- cmd-line opts (input)
420 -> [SimplifierSwitch] -- simplifier-switch accumulator
421 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
422 -> ([CoreToDo], [StgToDo]) -- result
424 -- "simpl_sep" tailcalls "sep" once it's seen one set
425 -- of SimplifierSwitches for a CoreDoSimplify.
428 simpl_sep input@[] simpl_sw core_td stg_td
429 = panic "simpl_sep []"
432 -- The SimplifierSwitches should be delimited by "[" and "]".
434 simpl_sep (opt1:opts) simpl_sw core_td stg_td
435 = case (_UNPK_ opt1) of
436 "[" -> simpl_sep opts simpl_sw core_td stg_td
438 this_simpl = CoreDoSimplify (isAmongSimpl simpl_sw)
440 sep opts (this_simpl : core_td) stg_td
442 # define SIMPL_SW(sw) simpl_sep opts (sw:simpl_sw) core_td stg_td
444 -- the non-"just match a string" options are at the end...
445 "-fcode-duplication-ok" -> SIMPL_SW(SimplOkToDupCode)
446 "-ffloat-lets-exposing-whnf" -> SIMPL_SW(SimplFloatLetsExposingWHNF)
447 "-ffloat-primops-ok" -> SIMPL_SW(SimplOkToFloatPrimOps)
448 "-falways-float-lets-from-lets" -> SIMPL_SW(SimplAlwaysFloatLetsFromLets)
449 "-fdo-case-elim" -> SIMPL_SW(SimplDoCaseElim)
450 "-fdo-lambda-eta-expansion" -> SIMPL_SW(SimplDoLambdaEtaExpansion)
451 "-fdo-foldr-build" -> SIMPL_SW(SimplDoFoldrBuild)
452 "-fdo-arity-expand" -> SIMPL_SW(SimplDoArityExpand)
453 "-fdo-inline-foldr-build" -> SIMPL_SW(SimplDoInlineFoldrBuild)
454 "-fcase-of-case" -> SIMPL_SW(SimplCaseOfCase)
455 "-fcase-merge" -> SIMPL_SW(SimplCaseMerge)
456 "-flet-to-case" -> SIMPL_SW(SimplLetToCase)
457 "-fpedantic-bottoms" -> SIMPL_SW(SimplPedanticBottoms)
458 "-fmay-delete-conjurable-ids" -> SIMPL_SW(SimplMayDeleteConjurableIds)
459 "-fessential-unfoldings-only" -> SIMPL_SW(EssentialUnfoldingsOnly)
460 "-fignore-inline-pragma" -> SIMPL_SW(IgnoreINLINEPragma)
461 "-fno-let-from-case" -> SIMPL_SW(SimplNoLetFromCase)
462 "-fno-let-from-app" -> SIMPL_SW(SimplNoLetFromApp)
463 "-fno-let-from-strict-let" -> SIMPL_SW(SimplNoLetFromStrictLet)
464 "-fclone-binds" -> SIMPL_SW(SimplPleaseClone)
466 o | starts_with_msi -> SIMPL_SW(MaxSimplifierIterations (read after_msi))
468 maybe_msi = startsWith "-fmax-simplifier-iterations" o
469 starts_with_msi = maybeToBool maybe_msi
470 (Just after_msi) = maybe_msi
472 _ -> -- NB: the driver is really supposed to handle bad options
473 simpl_sep opts simpl_sw core_td stg_td
476 %************************************************************************
478 \subsection{Switch ordering}
480 %************************************************************************
482 In spite of the @Produce*@ and @SccGroup@ constructors, these things
483 behave just like enumeration types.
486 instance Eq SimplifierSwitch where
487 a == b = tagOf_SimplSwitch a _EQ_ tagOf_SimplSwitch b
489 instance Ord SimplifierSwitch where
490 a < b = tagOf_SimplSwitch a _LT_ tagOf_SimplSwitch b
491 a <= b = tagOf_SimplSwitch a _LE_ tagOf_SimplSwitch b
493 tagOf_SimplSwitch SimplOkToDupCode =(ILIT(0) :: FAST_INT)
494 tagOf_SimplSwitch SimplFloatLetsExposingWHNF = ILIT(1)
495 tagOf_SimplSwitch SimplOkToFloatPrimOps = ILIT(2)
496 tagOf_SimplSwitch SimplAlwaysFloatLetsFromLets = ILIT(3)
497 tagOf_SimplSwitch SimplDoCaseElim = ILIT(4)
498 tagOf_SimplSwitch SimplCaseOfCase = ILIT(6)
499 tagOf_SimplSwitch SimplLetToCase = ILIT(7)
500 tagOf_SimplSwitch SimplMayDeleteConjurableIds = ILIT(9)
501 tagOf_SimplSwitch SimplPedanticBottoms = ILIT(10)
502 tagOf_SimplSwitch SimplDoArityExpand = ILIT(11)
503 tagOf_SimplSwitch SimplDoFoldrBuild = ILIT(12)
504 tagOf_SimplSwitch SimplDoInlineFoldrBuild = ILIT(14)
505 tagOf_SimplSwitch IgnoreINLINEPragma = ILIT(15)
506 tagOf_SimplSwitch SimplDoLambdaEtaExpansion = ILIT(16)
507 tagOf_SimplSwitch EssentialUnfoldingsOnly = ILIT(19)
508 tagOf_SimplSwitch (MaxSimplifierIterations _) = ILIT(21)
509 tagOf_SimplSwitch SimplNoLetFromCase = ILIT(27)
510 tagOf_SimplSwitch SimplNoLetFromApp = ILIT(28)
511 tagOf_SimplSwitch SimplNoLetFromStrictLet = ILIT(29)
512 tagOf_SimplSwitch SimplCaseMerge = ILIT(31)
513 tagOf_SimplSwitch SimplPleaseClone = ILIT(32)
515 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
517 tagOf_SimplSwitch _ = panic# "tagOf_SimplSwitch"
519 lAST_SIMPL_SWITCH_TAG = IBOX(tagOf_SimplSwitch SimplPleaseClone)
522 %************************************************************************
524 \subsection{Switch lookup}
526 %************************************************************************
529 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
531 isAmongSimpl on_switches -- Switches mentioned later occur *earlier*
532 -- in the list; defaults right at the end.
534 tidied_on_switches = foldl rm_dups [] on_switches
535 -- The fold*l* ensures that we keep the latest switches;
536 -- ie the ones that occur earliest in the list.
538 sw_tbl :: Array Int SwitchResult
540 sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
544 all_undefined = [ (i, SwBool False) | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
546 defined_elems = map mk_assoc_elem tidied_on_switches
548 -- (avoid some unboxing, bounds checking, and other horrible things:)
549 case sw_tbl of { Array bounds_who_needs_'em stuff ->
551 case (indexArray# stuff (tagOf_SimplSwitch switch)) of
552 #if __GLASGOW_HASKELL__ < 400
559 mk_assoc_elem k@(MaxSimplifierIterations lvl) = (IBOX(tagOf_SimplSwitch k), SwInt lvl)
561 mk_assoc_elem k = (IBOX(tagOf_SimplSwitch k), SwBool True) -- I'm here, Mom!
563 -- cannot have duplicates if we are going to use the array thing
564 rm_dups switches_so_far switch
565 = if switch `is_elem` switches_so_far
567 else switch : switches_so_far
569 sw `is_elem` [] = False
570 sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) _EQ_ (tagOf_SimplSwitch s)
574 Default settings for simplifier switches
577 defaultSimplSwitches = [MaxSimplifierIterations 1
581 %************************************************************************
583 \subsection{Misc functions for command-line options}
585 %************************************************************************
589 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
591 switchIsOn lookup_fn switch
592 = case (lookup_fn switch) of
593 SwBool False -> False
596 intSwitchSet :: (switch -> SwitchResult)
600 intSwitchSet lookup_fn switch
601 = case (lookup_fn (switch (panic "intSwitchSet"))) of
602 SwInt int -> Just int
607 startsWith, endsWith :: String -> String -> Maybe String
609 startsWith [] str = Just str
610 startsWith (c:cs) (s:ss)
611 = if c /= s then Nothing else startsWith cs ss
612 startsWith _ [] = Nothing
615 = case (startsWith (reverse cs) (reverse ss)) of
617 Just rs -> Just (reverse rs)