2 % (c) The AQUA Project, Glasgow University, 1996-98
4 \section[CmdLineOpts]{Things to do with command-line options}
29 opt_D_dump_occur_anal,
35 opt_D_dump_simpl_iterations,
36 opt_D_dump_simpl_stats,
42 opt_D_dump_worker_wrapper,
48 opt_D_verbose_core2core,
49 opt_D_verbose_stg2stg,
58 opt_WarnDuplicateExports,
60 opt_WarnIncompletePatterns,
61 opt_WarnMissingFields,
62 opt_WarnMissingMethods,
64 opt_WarnNameShadowing,
65 opt_WarnOverlappingPatterns,
66 opt_WarnSimplePatterns,
69 opt_WarnUnusedImports,
70 opt_WarnUnusedMatches,
74 opt_AutoSccsOnAllToplevs,
75 opt_AutoSccsOnExportedToplevs,
76 opt_AutoSccsOnIndividualCafs,
85 opt_MaxContextReductionDepth,
86 opt_AllowOverlappingInstances,
87 opt_AllowUndecidableInstances,
89 opt_IrrefutableTuples,
98 opt_LiberateCaseThreshold,
99 opt_StgDoLetNoEscapes,
102 opt_UnboxStrictFields,
103 opt_SimplNoPreInlining,
104 opt_SimplDoEtaReduction,
105 opt_SimplDoLambdaEtaExpansion,
108 opt_SimplPedanticBottoms,
111 opt_UF_HiFileThreshold,
112 opt_UF_CreationThreshold,
114 opt_UF_ScrutConDiscount,
115 opt_UF_FunAppDiscount,
116 opt_UF_PrimArgDiscount,
117 opt_UF_KeenessFactor,
123 opt_CompilingPrelude,
124 opt_EmitCExternDecls,
125 opt_EnsureSplittableC,
132 opt_IgnoreIfacePragmas,
134 opt_NoImplicitPrelude,
136 opt_OmitInterfacePragmas,
138 opt_ProduceExportCStubs,
139 opt_ProduceExportHStubs,
156 #include "HsVersions.h"
158 import Array ( array, (//) )
161 import Constants -- Default values for some flags
163 import FastString ( headFS )
164 import Maybes ( assocMaybe, firstJust, maybeToBool )
165 import Panic ( panic, panic# )
167 #if __GLASGOW_HASKELL__ < 301
168 import ArrBase ( Array(..) )
170 import PrelArr ( Array(..) )
174 A command-line {\em switch} is (generally) either on or off; e.g., the
175 ``verbose'' (-v) switch is either on or off. (The \tr{-G<group>}
176 switch is an exception; it's set to a string, or nothing.)
178 A list of {\em ToDo}s is things to be done in a particular part of
179 processing. A (fictitious) example for the Core-to-Core simplifier
180 might be: run the simplifier, then run the strictness analyser, then
181 run the simplifier again (three ``todos'').
183 There are three ``to-do processing centers'' at the moment. In the
184 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
185 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
186 (\tr{simplStg/SimplStg.lhs}).
189 %************************************************************************
191 \subsection{Datatypes associated with command-line options}
193 %************************************************************************
197 = SwBool Bool -- on/off
198 | SwString FAST_STRING -- nothing or a String
199 | SwInt Int -- nothing or an Int
203 data CoreToDo -- These are diff core-to-core passes,
204 -- which may be invoked in any order,
205 -- as many times as you like.
207 = CoreDoSimplify -- The core-to-core simplifier.
208 (SimplifierSwitch -> SwitchResult)
209 -- Each run of the simplifier can take a different
210 -- set of simplifier-specific flags.
217 | CoreDoWorkerWrapper
227 | StgDoUpdateAnalysis
229 | StgDoMassageForProfiling -- should be (next to) last
230 -- There's also setStgVarInfo, but its absolute "lastness"
231 -- is so critical that it is hardwired in (no flag).
236 data SimplifierSwitch
237 = MaxSimplifierIterations Int
238 | SimplInlinePhase Int
243 %************************************************************************
245 \subsection{Classifying command-line options}
247 %************************************************************************
250 lookUp :: FAST_STRING -> Bool
251 lookup_int :: String -> Maybe Int
252 lookup_def_int :: String -> Int -> Int
253 lookup_def_float :: String -> Float -> Float
254 lookup_str :: String -> Maybe String
256 lookUp sw = maybeToBool (assoc_opts sw)
258 lookup_str sw = firstJust (map (startsWith sw) unpacked_opts)
260 lookup_int sw = case (lookup_str sw) of
262 Just xx -> Just (read xx)
264 lookup_def_int sw def = case (lookup_str sw) of
265 Nothing -> def -- Use default
268 lookup_def_char sw def = case (lookup_str sw) of
270 _ -> def -- Use default
272 lookup_def_float sw def = case (lookup_str sw) of
273 Nothing -> def -- Use default
276 assoc_opts = assocMaybe [ (a, True) | a <- argv ]
277 unpacked_opts = map _UNPK_ argv
280 Putting the compiler options into temporary at-files
281 may turn out to be necessary later on if we turn hsc into
282 a pure Win32 application where I think there's a command-line
283 length limit of 255. unpacked_opts understands the @ option.
285 assoc_opts = assocMaybe [ (_PK_ a, True) | a <- unpacked_opts ]
287 unpacked_opts :: [String]
293 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
299 src_filename :: FAST_STRING
300 src_filename = case argv of
301 filename : rest | headFS filename /= '-' -> filename
302 otherwise -> panic "no filename"
307 opt_D_dump_all {- do not -} = lookUp SLIT("-ddump-all")
308 opt_D_dump_most {- export -} = opt_D_dump_all || lookUp SLIT("-ddump-most")
310 opt_D_dump_absC = opt_D_dump_all || lookUp SLIT("-ddump-absC")
311 opt_D_dump_asm = opt_D_dump_all || lookUp SLIT("-ddump-asm")
312 opt_D_dump_cpranal = opt_D_dump_most || lookUp SLIT("-ddump-cpranal")
313 opt_D_dump_deriv = opt_D_dump_most || lookUp SLIT("-ddump-deriv")
314 opt_D_dump_ds = opt_D_dump_most || lookUp SLIT("-ddump-ds")
315 opt_D_dump_flatC = opt_D_dump_all || lookUp SLIT("-ddump-flatC")
316 opt_D_dump_foreign = opt_D_dump_most || lookUp SLIT("-ddump-foreign-stubs")
317 opt_D_dump_inlinings = opt_D_dump_all || lookUp SLIT("-ddump-inlinings")
318 opt_D_dump_occur_anal = opt_D_dump_all || lookUp SLIT("-ddump-occur-anal")
319 opt_D_dump_parsed = opt_D_dump_most || lookUp SLIT("-ddump-parsed")
320 opt_D_dump_realC = opt_D_dump_all || lookUp SLIT("-ddump-realC")
321 opt_D_dump_rn = opt_D_dump_most || lookUp SLIT("-ddump-rn")
322 opt_D_dump_simpl = opt_D_dump_most || lookUp SLIT("-ddump-simpl")
323 opt_D_dump_simpl_iterations = opt_D_dump_all || lookUp SLIT("-ddump-simpl-iterations")
324 opt_D_dump_spec = opt_D_dump_most || lookUp SLIT("-ddump-spec")
325 opt_D_dump_stg = opt_D_dump_most || lookUp SLIT("-ddump-stg")
326 opt_D_dump_stranal = opt_D_dump_most || lookUp SLIT("-ddump-stranal")
327 opt_D_dump_tc = opt_D_dump_most || lookUp SLIT("-ddump-tc")
328 opt_D_dump_rules = opt_D_dump_most || lookUp SLIT("-ddump-rules")
329 opt_D_dump_usagesp = opt_D_dump_most || lookUp SLIT("-ddump-usagesp")
330 opt_D_dump_cse = opt_D_dump_most || lookUp SLIT("-ddump-cse")
331 opt_D_dump_worker_wrapper = opt_D_dump_most || lookUp SLIT("-ddump-workwrap")
332 opt_D_show_passes = opt_D_dump_most || lookUp SLIT("-dshow-passes")
333 opt_D_dump_rn_trace = opt_D_dump_all || lookUp SLIT("-ddump-rn-trace")
334 opt_D_dump_rn_stats = opt_D_dump_most || lookUp SLIT("-ddump-rn-stats")
335 opt_D_dump_stix = opt_D_dump_all || lookUp SLIT("-ddump-stix")
336 opt_D_dump_simpl_stats = opt_D_dump_most || lookUp SLIT("-ddump-simpl-stats")
337 opt_D_source_stats = opt_D_dump_most || lookUp SLIT("-dsource-stats")
338 opt_D_verbose_core2core = opt_D_dump_all || lookUp SLIT("-dverbose-simpl")
339 opt_D_verbose_stg2stg = opt_D_dump_all || lookUp SLIT("-dverbose-stg")
341 opt_DoCoreLinting = lookUp SLIT("-dcore-lint")
342 opt_DoStgLinting = lookUp SLIT("-dstg-lint")
343 opt_DoUSPLinting = lookUp SLIT("-dusagesp-lint")
344 opt_PprStyle_NoPrags = lookUp SLIT("-dppr-noprags")
345 opt_PprStyle_Debug = lookUp SLIT("-dppr-debug")
346 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
349 opt_WarnDuplicateExports = lookUp SLIT("-fwarn-duplicate-exports")
350 opt_WarnHiShadows = lookUp SLIT("-fwarn-hi-shadowing")
351 opt_WarnIncompletePatterns = lookUp SLIT("-fwarn-incomplete-patterns")
352 opt_WarnMissingFields = lookUp SLIT("-fwarn-missing-fields")
353 opt_WarnMissingMethods = lookUp SLIT("-fwarn-missing-methods")
354 opt_WarnMissingSigs = lookUp SLIT("-fwarn-missing-signatures")
355 opt_WarnNameShadowing = lookUp SLIT("-fwarn-name-shadowing")
356 opt_WarnOverlappingPatterns = lookUp SLIT("-fwarn-overlapping-patterns")
357 opt_WarnSimplePatterns = lookUp SLIT("-fwarn-simple-patterns")
358 opt_WarnTypeDefaults = lookUp SLIT("-fwarn-type-defaults")
359 opt_WarnUnusedBinds = lookUp SLIT("-fwarn-unused-binds")
360 opt_WarnUnusedImports = lookUp SLIT("-fwarn-unused-imports")
361 opt_WarnUnusedMatches = lookUp SLIT("-fwarn-unused-matches")
362 opt_WarnDeprecations = lookUp SLIT("-fwarn-deprecations")
365 opt_AutoSccsOnAllToplevs = lookUp SLIT("-fauto-sccs-on-all-toplevs")
366 opt_AutoSccsOnExportedToplevs = lookUp SLIT("-fauto-sccs-on-exported-toplevs")
367 opt_AutoSccsOnIndividualCafs = lookUp SLIT("-fauto-sccs-on-individual-cafs")
368 opt_AutoSccsOnDicts = lookUp SLIT("-fauto-sccs-on-dicts")
369 opt_SccGroup = lookup_str "-G="
370 opt_SccProfilingOn = lookUp SLIT("-fscc-profiling")
371 opt_DoTickyProfiling = lookUp SLIT("-fticky-ticky")
374 opt_AllStrict = lookUp SLIT("-fall-strict")
375 opt_DictsStrict = lookUp SLIT("-fdicts-strict")
376 opt_AllowOverlappingInstances = lookUp SLIT("-fallow-overlapping-instances")
377 opt_AllowUndecidableInstances = lookUp SLIT("-fallow-undecidable-instances")
378 opt_GlasgowExts = lookUp SLIT("-fglasgow-exts")
379 opt_IrrefutableTuples = lookUp SLIT("-firrefutable-tuples")
380 opt_MaxContextReductionDepth = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
381 opt_NumbersStrict = lookUp SLIT("-fnumbers-strict")
382 opt_Parallel = lookUp SLIT("-fparallel")
383 opt_SMP = lookUp SLIT("-fsmp")
386 opt_DoEtaReduction = lookUp SLIT("-fdo-eta-reduction")
387 opt_DoSemiTagging = lookUp SLIT("-fsemi-tagging")
388 opt_FoldrBuildOn = lookUp SLIT("-ffoldr-build-on")
389 opt_LiberateCaseThreshold = lookup_def_int "-fliberate-case-threshold" (10::Int)
390 opt_StgDoLetNoEscapes = lookUp SLIT("-flet-no-escape")
391 opt_UnfoldCasms = lookUp SLIT("-funfold-casms-in-hi-file")
392 opt_UsageSPOn = lookUp SLIT("-fusagesp-on")
393 opt_UnboxStrictFields = lookUp SLIT("-funbox-strict-fields")
396 It's a bit unfortunate to have to re-introduce this chap, but on Win32
397 platforms we do need a way of distinguishing between the case when we're
398 compiling a static version of the Prelude and one that's going to be
399 put into a DLL. Why? Because the compiler's wired in modules need to
400 be attributed as either coming from a DLL or not.
402 opt_CompilingPrelude = lookUp SLIT("-fcompiling-prelude")
403 opt_EmitCExternDecls = lookUp SLIT("-femit-extern-decls")
404 opt_EnsureSplittableC = lookUp SLIT("-fglobalise-toplev-names")
405 opt_GranMacros = lookUp SLIT("-fgransim")
406 opt_HiMap = lookup_str "-himap=" -- file saying where to look for .hi files
407 opt_HiMapSep = lookup_def_char "-himap-sep=" ':'
408 opt_HiVersion = lookup_def_int "-fhi-version=" 0 -- what version we're compiling.
409 opt_HistorySize = lookup_def_int "-fhistory-size" 20
410 opt_IgnoreAsserts = lookUp SLIT("-fignore-asserts")
411 opt_IgnoreIfacePragmas = lookUp SLIT("-fignore-interface-pragmas")
412 opt_NoHiCheck = lookUp SLIT("-fno-hi-version-check")
413 opt_NoImplicitPrelude = lookUp SLIT("-fno-implicit-prelude")
414 opt_OmitBlackHoling = lookUp SLIT("-dno-black-holing")
415 opt_OmitInterfacePragmas = lookUp SLIT("-fomit-interface-pragmas")
416 opt_ProduceC = lookup_str "-C="
417 opt_ProduceExportCStubs = lookup_str "-F="
418 opt_ProduceExportHStubs = lookup_str "-FH="
419 opt_ProduceHi = lookup_str "-hifile=" -- the one to produce this time
421 -- Simplifier switches
422 opt_SimplNoPreInlining = lookUp SLIT("-fno-pre-inlining")
423 -- NoPreInlining is there just to see how bad things
424 -- get if you don't do it!
425 opt_SimplDoEtaReduction = lookUp SLIT("-fdo-eta-reduction")
426 opt_SimplDoLambdaEtaExpansion = lookUp SLIT("-fdo-lambda-eta-expansion")
427 opt_SimplCaseOfCase = lookUp SLIT("-fcase-of-case")
428 opt_SimplCaseMerge = lookUp SLIT("-fcase-merge")
429 opt_SimplPedanticBottoms = lookUp SLIT("-fpedantic-bottoms")
432 opt_UF_HiFileThreshold = lookup_def_int "-funfolding-interface-threshold" (30::Int)
433 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (30::Int)
434 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (8::Int) -- Discounts can be big
435 opt_UF_ScrutConDiscount = lookup_def_int "-funfolding-con-discount" (2::Int)
436 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int) -- It's great to inline a fn
437 opt_UF_PrimArgDiscount = lookup_def_int "-funfolding-prim-discount" (1::Int)
438 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (2.0::Float)
440 opt_UF_CheapOp = ( 0 :: Int) -- Only one instruction; and the args are charged for
441 opt_UF_DearOp = ( 4 :: Int)
442 opt_UF_NoRepLit = ( 20 :: Int) -- Strings can be pretty big
444 opt_ProduceS = lookup_str "-S="
445 opt_ReportCompile = lookUp SLIT("-freport-compile")
446 opt_NoPruneDecls = lookUp SLIT("-fno-prune-decls")
447 opt_SourceUnchanged = lookUp SLIT("-fsource-unchanged")
448 opt_Static = lookUp SLIT("-static")
449 opt_Unregisterised = lookUp SLIT("-funregisterised")
450 opt_Verbose = lookUp SLIT("-v")
452 opt_UseVanillaRegs | opt_Unregisterised = 0
453 | otherwise = mAX_Real_Vanilla_REG
454 opt_UseFloatRegs | opt_Unregisterised = 0
455 | otherwise = mAX_Real_Float_REG
456 opt_UseDoubleRegs | opt_Unregisterised = 0
457 | otherwise = mAX_Real_Double_REG
458 opt_UseLongRegs | opt_Unregisterised = 0
459 | otherwise = mAX_Real_Long_REG
463 classifyOpts :: ([CoreToDo], -- Core-to-Core processing spec
464 [StgToDo]) -- STG-to-STG processing spec
466 classifyOpts = sep argv [] [] -- accumulators...
468 sep :: [FAST_STRING] -- cmd-line opts (input)
469 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
470 -> ([CoreToDo], [StgToDo]) -- result
472 sep [] core_td stg_td -- all done!
473 = (reverse core_td, reverse stg_td)
475 # define CORE_TD(to_do) sep opts (to_do:core_td) stg_td
476 # define STG_TD(to_do) sep opts core_td (to_do:stg_td)
478 sep (opt1:opts) core_td stg_td
479 = case (_UNPK_ opt1) of -- the non-"just match a string" options are at the end...
480 ',' : _ -> sep opts core_td stg_td -- it is for the parser
482 "-fsimplify" -> -- gather up SimplifierSwitches specially...
483 simpl_sep opts defaultSimplSwitches core_td stg_td
485 "-ffloat-inwards" -> CORE_TD(CoreDoFloatInwards)
486 "-ffull-laziness" -> CORE_TD(CoreDoFullLaziness)
487 "-fliberate-case" -> CORE_TD(CoreLiberateCase)
488 "-fcse" -> CORE_TD(CoreCSE)
489 "-fprint-core" -> CORE_TD(CoreDoPrintCore)
490 "-fstatic-args" -> CORE_TD(CoreDoStaticArgs)
491 "-fstrictness" -> CORE_TD(CoreDoStrictness)
492 "-fworker-wrapper" -> CORE_TD(CoreDoWorkerWrapper)
493 "-fspecialise" -> CORE_TD(CoreDoSpecialising)
494 "-fusagesp" -> CORE_TD(CoreDoUSPInf)
495 "-fcpr-analyse" -> CORE_TD(CoreDoCPResult)
497 "-fstg-static-args" -> STG_TD(StgDoStaticArgs)
498 "-fupdate-analysis" -> STG_TD(StgDoUpdateAnalysis)
499 "-dstg-stats" -> STG_TD(D_stg_stats)
500 "-flambda-lift" -> STG_TD(StgDoLambdaLift)
501 "-fmassage-stg-for-profiling" -> STG_TD(StgDoMassageForProfiling)
503 _ -> -- NB: the driver is really supposed to handle bad options
504 sep opts core_td stg_td
508 simpl_sep :: [FAST_STRING] -- cmd-line opts (input)
509 -> [SimplifierSwitch] -- simplifier-switch accumulator
510 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
511 -> ([CoreToDo], [StgToDo]) -- result
513 -- "simpl_sep" tailcalls "sep" once it's seen one set
514 -- of SimplifierSwitches for a CoreDoSimplify.
517 simpl_sep input@[] simpl_sw core_td stg_td
518 = panic "simpl_sep []"
521 -- The SimplifierSwitches should be delimited by "[" and "]".
523 simpl_sep (opt1:opts) simpl_sw core_td stg_td
524 = case (_UNPK_ opt1) of
525 "[" -> simpl_sep opts simpl_sw core_td stg_td
527 this_simpl = CoreDoSimplify (isAmongSimpl simpl_sw)
529 sep opts (this_simpl : core_td) stg_td
531 opt -> case matchSimplSw opt of
532 Just sw -> simpl_sep opts (sw:simpl_sw) core_td stg_td
533 Nothing -> simpl_sep opts simpl_sw core_td stg_td
536 = firstJust [ matchSwInt opt "-fmax-simplifier-iterations" MaxSimplifierIterations
537 , matchSwInt opt "-finline-phase" SimplInlinePhase
538 , matchSwBool opt "-fno-rules" DontApplyRules
539 , matchSwBool opt "-flet-to-case" SimplLetToCase
542 matchSwBool :: String -> String -> a -> Maybe a
543 matchSwBool opt str sw | opt == str = Just sw
544 | otherwise = Nothing
546 matchSwInt :: String -> String -> (Int -> a) -> Maybe a
547 matchSwInt opt str sw = case startsWith str opt of
548 Just opt_left -> Just (sw (read opt_left))
552 %************************************************************************
554 \subsection{Switch ordering}
556 %************************************************************************
558 In spite of the @Produce*@ and @SccGroup@ constructors, these things
559 behave just like enumeration types.
562 instance Eq SimplifierSwitch where
563 a == b = tagOf_SimplSwitch a _EQ_ tagOf_SimplSwitch b
565 instance Ord SimplifierSwitch where
566 a < b = tagOf_SimplSwitch a _LT_ tagOf_SimplSwitch b
567 a <= b = tagOf_SimplSwitch a _LE_ tagOf_SimplSwitch b
570 tagOf_SimplSwitch (SimplInlinePhase _) = ILIT(1)
571 tagOf_SimplSwitch (MaxSimplifierIterations _) = ILIT(2)
572 tagOf_SimplSwitch DontApplyRules = ILIT(3)
573 tagOf_SimplSwitch SimplLetToCase = ILIT(4)
575 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
577 lAST_SIMPL_SWITCH_TAG = 4
580 %************************************************************************
582 \subsection{Switch lookup}
584 %************************************************************************
587 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
589 isAmongSimpl on_switches -- Switches mentioned later occur *earlier*
590 -- in the list; defaults right at the end.
592 tidied_on_switches = foldl rm_dups [] on_switches
593 -- The fold*l* ensures that we keep the latest switches;
594 -- ie the ones that occur earliest in the list.
596 sw_tbl :: Array Int SwitchResult
597 sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
601 all_undefined = [ (i, SwBool False) | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
603 defined_elems = map mk_assoc_elem tidied_on_switches
605 -- (avoid some unboxing, bounds checking, and other horrible things:)
606 #if __GLASGOW_HASKELL__ < 405
607 case sw_tbl of { Array bounds_who_needs_'em stuff ->
609 case sw_tbl of { Array _ _ stuff ->
612 case (indexArray# stuff (tagOf_SimplSwitch switch)) of
613 #if __GLASGOW_HASKELL__ < 400
615 #elif __GLASGOW_HASKELL__ < 403
622 mk_assoc_elem k@(MaxSimplifierIterations lvl) = (IBOX(tagOf_SimplSwitch k), SwInt lvl)
623 mk_assoc_elem k@(SimplInlinePhase n) = (IBOX(tagOf_SimplSwitch k), SwInt n)
624 mk_assoc_elem k = (IBOX(tagOf_SimplSwitch k), SwBool True) -- I'm here, Mom!
626 -- cannot have duplicates if we are going to use the array thing
627 rm_dups switches_so_far switch
628 = if switch `is_elem` switches_so_far
630 else switch : switches_so_far
632 sw `is_elem` [] = False
633 sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) _EQ_ (tagOf_SimplSwitch s)
637 Default settings for simplifier switches
640 defaultSimplSwitches = [MaxSimplifierIterations 1]
643 %************************************************************************
645 \subsection{Misc functions for command-line options}
647 %************************************************************************
651 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
653 switchIsOn lookup_fn switch
654 = case (lookup_fn switch) of
655 SwBool False -> False
658 intSwitchSet :: (switch -> SwitchResult)
662 intSwitchSet lookup_fn switch
663 = case (lookup_fn (switch (panic "intSwitchSet"))) of
664 SwInt int -> Just int
669 startsWith :: String -> String -> Maybe String
670 -- startsWith pfx (pfx++rest) = Just rest
672 startsWith [] str = Just str
673 startsWith (c:cs) (s:ss)
674 = if c /= s then Nothing else startsWith cs ss
675 startsWith _ [] = Nothing
677 endsWith :: String -> String -> Maybe String
679 = case (startsWith (reverse cs) (reverse ss)) of
681 Just rs -> Just (reverse rs)