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,
47 opt_D_verbose_core2core,
48 opt_D_verbose_stg2stg,
57 opt_WarnDuplicateExports,
59 opt_WarnIncompletePatterns,
60 opt_WarnMissingFields,
61 opt_WarnMissingMethods,
63 opt_WarnNameShadowing,
64 opt_WarnOverlappingPatterns,
65 opt_WarnSimplePatterns,
68 opt_WarnUnusedImports,
69 opt_WarnUnusedMatches,
72 opt_AutoSccsOnAllToplevs,
73 opt_AutoSccsOnExportedToplevs,
74 opt_AutoSccsOnIndividualCafs,
83 opt_MaxContextReductionDepth,
84 opt_AllowOverlappingInstances,
85 opt_AllowUndecidableInstances,
87 opt_IrrefutableTuples,
95 opt_LiberateCaseThreshold,
97 opt_StgDoLetNoEscapes,
100 opt_UnboxStrictFields,
101 opt_SimplNoPreInlining,
102 opt_SimplDoEtaReduction,
103 opt_SimplDoLambdaEtaExpansion,
107 opt_SimplPedanticBottoms,
110 opt_UF_HiFileThreshold,
111 opt_UF_CreationThreshold,
113 opt_UF_ScrutConDiscount,
114 opt_UF_FunAppDiscount,
115 opt_UF_PrimArgDiscount,
116 opt_UF_KeenessFactor,
122 opt_CompilingPrelude,
123 opt_EmitCExternDecls,
124 opt_EnsureSplittableC,
131 opt_IgnoreIfacePragmas,
133 opt_NoImplicitPrelude,
135 opt_OmitInterfacePragmas,
137 opt_ProduceExportCStubs,
138 opt_ProduceExportHStubs,
155 #include "HsVersions.h"
157 import Array ( array, (//) )
160 import Constants -- Default values for some flags
162 import FastString ( headFS )
163 import Maybes ( assocMaybe, firstJust, maybeToBool )
164 import Panic ( panic, panic# )
166 #if __GLASGOW_HASKELL__ < 301
167 import ArrBase ( Array(..) )
169 import PrelArr ( Array(..) )
173 A command-line {\em switch} is (generally) either on or off; e.g., the
174 ``verbose'' (-v) switch is either on or off. (The \tr{-G<group>}
175 switch is an exception; it's set to a string, or nothing.)
177 A list of {\em ToDo}s is things to be done in a particular part of
178 processing. A (fictitious) example for the Core-to-Core simplifier
179 might be: run the simplifier, then run the strictness analyser, then
180 run the simplifier again (three ``todos'').
182 There are three ``to-do processing centers'' at the moment. In the
183 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
184 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
185 (\tr{simplStg/SimplStg.lhs}).
188 %************************************************************************
190 \subsection{Datatypes associated with command-line options}
192 %************************************************************************
196 = SwBool Bool -- on/off
197 | SwString FAST_STRING -- nothing or a String
198 | SwInt Int -- nothing or an Int
202 data CoreToDo -- These are diff core-to-core passes,
203 -- which may be invoked in any order,
204 -- as many times as you like.
206 = CoreDoSimplify -- The core-to-core simplifier.
207 (SimplifierSwitch -> SwitchResult)
208 -- Each run of the simplifier can take a different
209 -- set of simplifier-specific flags.
216 | CoreDoWorkerWrapper
226 | StgDoUpdateAnalysis
228 | StgDoMassageForProfiling -- should be (next to) last
229 -- There's also setStgVarInfo, but its absolute "lastness"
230 -- is so critical that it is hardwired in (no flag).
235 data SimplifierSwitch
236 = MaxSimplifierIterations Int
237 | SimplInlinePhase Int
240 %************************************************************************
242 \subsection{Classifying command-line options}
244 %************************************************************************
247 lookUp :: FAST_STRING -> Bool
248 lookup_int :: String -> Maybe Int
249 lookup_def_int :: String -> Int -> Int
250 lookup_def_float :: String -> Float -> Float
251 lookup_str :: String -> Maybe String
253 lookUp sw = maybeToBool (assoc_opts sw)
255 lookup_str sw = firstJust (map (startsWith sw) unpacked_opts)
257 lookup_int sw = case (lookup_str sw) of
259 Just xx -> Just (read xx)
261 lookup_def_int sw def = case (lookup_str sw) of
262 Nothing -> def -- Use default
265 lookup_def_char sw def = case (lookup_str sw) of
267 _ -> def -- Use default
269 lookup_def_float sw def = case (lookup_str sw) of
270 Nothing -> def -- Use default
273 assoc_opts = assocMaybe [ (a, True) | a <- argv ]
274 unpacked_opts = map _UNPK_ argv
277 Putting the compiler options into temporary at-files
278 may turn out to be necessary later on if we turn hsc into
279 a pure Win32 application where I think there's a command-line
280 length limit of 255. unpacked_opts understands the @ option.
282 assoc_opts = assocMaybe [ (_PK_ a, True) | a <- unpacked_opts ]
284 unpacked_opts :: [String]
290 expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
296 src_filename :: FAST_STRING
297 src_filename = case argv of
298 filename : rest | headFS filename /= '-' -> filename
299 otherwise -> panic "no filename"
304 opt_D_dump_all {- do not -} = lookUp SLIT("-ddump-all")
305 opt_D_dump_most {- export -} = opt_D_dump_all || lookUp SLIT("-ddump-most")
307 opt_D_dump_absC = opt_D_dump_all || lookUp SLIT("-ddump-absC")
308 opt_D_dump_asm = opt_D_dump_all || lookUp SLIT("-ddump-asm")
309 opt_D_dump_cpranal = opt_D_dump_most || lookUp SLIT("-ddump-cpranal")
310 opt_D_dump_deriv = opt_D_dump_most || lookUp SLIT("-ddump-deriv")
311 opt_D_dump_ds = opt_D_dump_most || lookUp SLIT("-ddump-ds")
312 opt_D_dump_flatC = opt_D_dump_all || lookUp SLIT("-ddump-flatC")
313 opt_D_dump_foreign = opt_D_dump_most || lookUp SLIT("-ddump-foreign-stubs")
314 opt_D_dump_inlinings = opt_D_dump_all || lookUp SLIT("-ddump-inlinings")
315 opt_D_dump_occur_anal = opt_D_dump_most || lookUp SLIT("-ddump-occur-anal")
316 opt_D_dump_parsed = opt_D_dump_most || lookUp SLIT("-ddump-parsed")
317 opt_D_dump_realC = opt_D_dump_all || lookUp SLIT("-ddump-realC")
318 opt_D_dump_rn = opt_D_dump_most || lookUp SLIT("-ddump-rn")
319 opt_D_dump_simpl = opt_D_dump_most || lookUp SLIT("-ddump-simpl")
320 opt_D_dump_simpl_iterations = opt_D_dump_all || lookUp SLIT("-ddump-simpl-iterations")
321 opt_D_dump_spec = opt_D_dump_most || lookUp SLIT("-ddump-spec")
322 opt_D_dump_stg = opt_D_dump_most || lookUp SLIT("-ddump-stg")
323 opt_D_dump_stranal = opt_D_dump_most || lookUp SLIT("-ddump-stranal")
324 opt_D_dump_tc = opt_D_dump_most || lookUp SLIT("-ddump-tc")
325 opt_D_dump_rules = opt_D_dump_most || lookUp SLIT("-ddump-rules")
326 opt_D_dump_usagesp = opt_D_dump_most || lookUp SLIT("-ddump-usagesp")
327 opt_D_dump_cse = opt_D_dump_most || lookUp SLIT("-ddump-cse")
328 opt_D_dump_worker_wrapper = opt_D_dump_most || lookUp SLIT("-ddump-workwrap")
329 opt_D_show_passes = opt_D_dump_most || lookUp SLIT("-dshow-passes")
330 opt_D_dump_rn_trace = opt_D_dump_all || lookUp SLIT("-ddump-rn-trace")
331 opt_D_dump_rn_stats = opt_D_dump_most || lookUp SLIT("-ddump-rn-stats")
332 opt_D_dump_simpl_stats = opt_D_dump_most || lookUp SLIT("-ddump-simpl-stats")
333 opt_D_source_stats = opt_D_dump_most || lookUp SLIT("-dsource-stats")
334 opt_D_verbose_core2core = opt_D_dump_all || lookUp SLIT("-dverbose-simpl")
335 opt_D_verbose_stg2stg = opt_D_dump_all || lookUp SLIT("-dverbose-stg")
337 opt_DoCoreLinting = lookUp SLIT("-dcore-lint")
338 opt_DoStgLinting = lookUp SLIT("-dstg-lint")
339 opt_DoUSPLinting = lookUp SLIT("-dusagesp-lint")
340 opt_PprStyle_NoPrags = lookUp SLIT("-dppr-noprags")
341 opt_PprStyle_Debug = lookUp SLIT("-dppr-debug")
342 opt_PprUserLength = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
345 opt_WarnDuplicateExports = lookUp SLIT("-fwarn-duplicate-exports")
346 opt_WarnHiShadows = lookUp SLIT("-fwarn-hi-shadowing")
347 opt_WarnIncompletePatterns = lookUp SLIT("-fwarn-incomplete-patterns")
348 opt_WarnMissingFields = lookUp SLIT("-fwarn-missing-fields")
349 opt_WarnMissingMethods = lookUp SLIT("-fwarn-missing-methods")
350 opt_WarnMissingSigs = lookUp SLIT("-fwarn-missing-signatures")
351 opt_WarnNameShadowing = lookUp SLIT("-fwarn-name-shadowing")
352 opt_WarnOverlappingPatterns = lookUp SLIT("-fwarn-overlapping-patterns")
353 opt_WarnSimplePatterns = lookUp SLIT("-fwarn-simple-patterns")
354 opt_WarnTypeDefaults = lookUp SLIT("-fwarn-type-defaults")
355 opt_WarnUnusedBinds = lookUp SLIT("-fwarn-unused-binds")
356 opt_WarnUnusedImports = lookUp SLIT("-fwarn-unused-imports")
357 opt_WarnUnusedMatches = lookUp SLIT("-fwarn-unused-matches")
360 opt_AutoSccsOnAllToplevs = lookUp SLIT("-fauto-sccs-on-all-toplevs")
361 opt_AutoSccsOnExportedToplevs = lookUp SLIT("-fauto-sccs-on-exported-toplevs")
362 opt_AutoSccsOnIndividualCafs = lookUp SLIT("-fauto-sccs-on-individual-cafs")
363 opt_AutoSccsOnDicts = lookUp SLIT("-fauto-sccs-on-dicts")
364 opt_SccGroup = lookup_str "-G="
365 opt_SccProfilingOn = lookUp SLIT("-fscc-profiling")
366 opt_DoTickyProfiling = lookUp SLIT("-fticky-ticky")
369 opt_AllStrict = lookUp SLIT("-fall-strict")
370 opt_DictsStrict = lookUp SLIT("-fdicts-strict")
371 opt_AllowOverlappingInstances = lookUp SLIT("-fallow-overlapping-instances")
372 opt_AllowUndecidableInstances = lookUp SLIT("-fallow-undecidable-instances")
373 opt_GlasgowExts = lookUp SLIT("-fglasgow-exts")
374 opt_IrrefutableTuples = lookUp SLIT("-firrefutable-tuples")
375 opt_MaxContextReductionDepth = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
376 opt_NumbersStrict = lookUp SLIT("-fnumbers-strict")
377 opt_Parallel = lookUp SLIT("-fparallel")
380 opt_DoEtaReduction = lookUp SLIT("-fdo-eta-reduction")
381 opt_DoSemiTagging = lookUp SLIT("-fsemi-tagging")
382 opt_FoldrBuildOn = lookUp SLIT("-ffoldr-build-on")
383 opt_LiberateCaseThreshold = lookup_def_int "-fliberate-case-threshold" (10::Int)
384 opt_NoPreInlining = lookUp SLIT("-fno-pre-inlining")
385 opt_StgDoLetNoEscapes = lookUp SLIT("-flet-no-escape")
386 opt_UnfoldCasms = lookUp SLIT("-funfold-casms-in-hi-file")
387 opt_UsageSPOn = lookUp SLIT("-fusagesp-on")
388 opt_UnboxStrictFields = lookUp SLIT("-funbox-strict-fields")
391 It's a bit unfortunate to have to re-introduce this chap, but on Win32
392 platforms we do need a way of distinguishing between the case when we're
393 compiling a static version of the Prelude and one that's going to be
394 put into a DLL. Why? Because the compiler's wired in modules need to
395 be attributed as either coming from a DLL or not.
397 opt_CompilingPrelude = lookUp SLIT("-fcompiling-prelude")
398 opt_EmitCExternDecls = lookUp SLIT("-femit-extern-decls")
399 opt_EnsureSplittableC = lookUp SLIT("-fglobalise-toplev-names")
400 opt_GranMacros = lookUp SLIT("-fgransim")
401 opt_HiMap = lookup_str "-himap=" -- file saying where to look for .hi files
402 opt_HiMapSep = lookup_def_char "-himap-sep=" ':'
403 opt_HiVersion = lookup_def_int "-fhi-version=" 0 -- what version we're compiling.
404 opt_HistorySize = lookup_def_int "-fhistory-size" 20
405 opt_IgnoreAsserts = lookUp SLIT("-fignore-asserts")
406 opt_IgnoreIfacePragmas = lookUp SLIT("-fignore-interface-pragmas")
407 opt_NoHiCheck = lookUp SLIT("-fno-hi-version-check")
408 opt_NoImplicitPrelude = lookUp SLIT("-fno-implicit-prelude")
409 opt_OmitBlackHoling = lookUp SLIT("-dno-black-holing")
410 opt_OmitInterfacePragmas = lookUp SLIT("-fomit-interface-pragmas")
411 opt_ProduceC = lookup_str "-C="
412 opt_ProduceExportCStubs = lookup_str "-F="
413 opt_ProduceExportHStubs = lookup_str "-FH="
414 opt_ProduceHi = lookup_str "-hifile=" -- the one to produce this time
416 -- Simplifier switches
417 opt_SimplNoPreInlining = lookUp SLIT("-fno-pre-inlining")
418 -- NoPreInlining is there just to see how bad things
419 -- get if you don't do it!
420 opt_SimplDoEtaReduction = lookUp SLIT("-fdo-eta-reduction")
421 opt_SimplDoLambdaEtaExpansion = lookUp SLIT("-fdo-lambda-eta-expansion")
422 opt_SimplCaseOfCase = lookUp SLIT("-fcase-of-case")
423 opt_SimplCaseMerge = lookUp SLIT("-fcase-merge")
424 opt_SimplLetToCase = lookUp SLIT("-flet-to-case")
425 opt_SimplPedanticBottoms = lookUp SLIT("-fpedantic-bottoms")
428 opt_UF_HiFileThreshold = lookup_def_int "-funfolding-interface-threshold" (30::Int)
429 opt_UF_CreationThreshold = lookup_def_int "-funfolding-creation-threshold" (30::Int)
430 opt_UF_UseThreshold = lookup_def_int "-funfolding-use-threshold" (8::Int) -- Discounts can be big
431 opt_UF_ScrutConDiscount = lookup_def_int "-funfolding-con-discount" (2::Int)
432 opt_UF_FunAppDiscount = lookup_def_int "-funfolding-fun-discount" (6::Int) -- It's great to inline a fn
433 opt_UF_PrimArgDiscount = lookup_def_int "-funfolding-prim-discount" (1::Int)
434 opt_UF_KeenessFactor = lookup_def_float "-funfolding-keeness-factor" (2.0::Float)
436 opt_UF_CheapOp = ( 0 :: Int) -- Only one instruction; and the args are charged for
437 opt_UF_DearOp = ( 4 :: Int)
438 opt_UF_NoRepLit = ( 20 :: Int) -- Strings can be pretty big
440 opt_ProduceS = lookup_str "-S="
441 opt_ReportCompile = lookUp SLIT("-freport-compile")
442 opt_NoPruneDecls = lookUp SLIT("-fno-prune-decls")
443 opt_SourceUnchanged = lookUp SLIT("-fsource-unchanged")
444 opt_Static = lookUp SLIT("-static")
445 opt_Unregisterised = lookUp SLIT("-funregisterised")
446 opt_Verbose = lookUp SLIT("-v")
448 opt_UseVanillaRegs | opt_Unregisterised = 0
449 | otherwise = mAX_Real_Vanilla_REG
450 opt_UseFloatRegs | opt_Unregisterised = 0
451 | otherwise = mAX_Real_Float_REG
452 opt_UseDoubleRegs | opt_Unregisterised = 0
453 | otherwise = mAX_Real_Double_REG
454 opt_UseLongRegs | opt_Unregisterised = 0
455 | otherwise = mAX_Real_Long_REG
459 classifyOpts :: ([CoreToDo], -- Core-to-Core processing spec
460 [StgToDo]) -- STG-to-STG processing spec
462 classifyOpts = sep argv [] [] -- accumulators...
464 sep :: [FAST_STRING] -- cmd-line opts (input)
465 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
466 -> ([CoreToDo], [StgToDo]) -- result
468 sep [] core_td stg_td -- all done!
469 = (reverse core_td, reverse stg_td)
471 # define CORE_TD(to_do) sep opts (to_do:core_td) stg_td
472 # define STG_TD(to_do) sep opts core_td (to_do:stg_td)
474 sep (opt1:opts) core_td stg_td
475 = case (_UNPK_ opt1) of -- the non-"just match a string" options are at the end...
476 ',' : _ -> sep opts core_td stg_td -- it is for the parser
478 "-fsimplify" -> -- gather up SimplifierSwitches specially...
479 simpl_sep opts defaultSimplSwitches core_td stg_td
481 "-ffloat-inwards" -> CORE_TD(CoreDoFloatInwards)
482 "-ffull-laziness" -> CORE_TD(CoreDoFullLaziness)
483 "-fliberate-case" -> CORE_TD(CoreLiberateCase)
484 "-fcse" -> CORE_TD(CoreCSE)
485 "-fprint-core" -> CORE_TD(CoreDoPrintCore)
486 "-fstatic-args" -> CORE_TD(CoreDoStaticArgs)
487 "-fstrictness" -> CORE_TD(CoreDoStrictness)
488 "-fworker-wrapper" -> CORE_TD(CoreDoWorkerWrapper)
489 "-fspecialise" -> CORE_TD(CoreDoSpecialising)
490 "-fusagesp" -> CORE_TD(CoreDoUSPInf)
491 "-fcpr-analyse" -> CORE_TD(CoreDoCPResult)
493 "-fstg-static-args" -> STG_TD(StgDoStaticArgs)
494 "-fupdate-analysis" -> STG_TD(StgDoUpdateAnalysis)
495 "-dstg-stats" -> STG_TD(D_stg_stats)
496 "-flambda-lift" -> STG_TD(StgDoLambdaLift)
497 "-fmassage-stg-for-profiling" -> STG_TD(StgDoMassageForProfiling)
499 _ -> -- NB: the driver is really supposed to handle bad options
500 sep opts core_td stg_td
504 simpl_sep :: [FAST_STRING] -- cmd-line opts (input)
505 -> [SimplifierSwitch] -- simplifier-switch accumulator
506 -> [CoreToDo] -> [StgToDo] -- to_do accumulators
507 -> ([CoreToDo], [StgToDo]) -- result
509 -- "simpl_sep" tailcalls "sep" once it's seen one set
510 -- of SimplifierSwitches for a CoreDoSimplify.
513 simpl_sep input@[] simpl_sw core_td stg_td
514 = panic "simpl_sep []"
517 -- The SimplifierSwitches should be delimited by "[" and "]".
519 simpl_sep (opt1:opts) simpl_sw core_td stg_td
520 = case (_UNPK_ opt1) of
521 "[" -> simpl_sep opts simpl_sw core_td stg_td
523 this_simpl = CoreDoSimplify (isAmongSimpl simpl_sw)
525 sep opts (this_simpl : core_td) stg_td
527 opt -> case matchSimplSw opt of
528 Just sw -> simpl_sep opts (sw:simpl_sw) core_td stg_td
529 Nothing -> simpl_sep opts simpl_sw core_td stg_td
532 = firstJust [ matchSwInt opt "-fmax-simplifier-iterations" MaxSimplifierIterations
533 , matchSwInt opt "-finline-phase" SimplInlinePhase
536 matchSwBool :: String -> String -> a -> Maybe a
537 matchSwBool opt str sw | opt == str = Just sw
538 | otherwise = Nothing
540 matchSwInt :: String -> String -> (Int -> a) -> Maybe a
541 matchSwInt opt str sw = case startsWith str opt of
542 Just opt_left -> Just (sw (read opt_left))
546 %************************************************************************
548 \subsection{Switch ordering}
550 %************************************************************************
552 In spite of the @Produce*@ and @SccGroup@ constructors, these things
553 behave just like enumeration types.
556 instance Eq SimplifierSwitch where
557 a == b = tagOf_SimplSwitch a _EQ_ tagOf_SimplSwitch b
559 instance Ord SimplifierSwitch where
560 a < b = tagOf_SimplSwitch a _LT_ tagOf_SimplSwitch b
561 a <= b = tagOf_SimplSwitch a _LE_ tagOf_SimplSwitch b
564 tagOf_SimplSwitch (SimplInlinePhase _) = ILIT(1)
565 tagOf_SimplSwitch (MaxSimplifierIterations _) = ILIT(2)
567 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
569 lAST_SIMPL_SWITCH_TAG = 2
572 %************************************************************************
574 \subsection{Switch lookup}
576 %************************************************************************
579 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
581 isAmongSimpl on_switches -- Switches mentioned later occur *earlier*
582 -- in the list; defaults right at the end.
584 tidied_on_switches = foldl rm_dups [] on_switches
585 -- The fold*l* ensures that we keep the latest switches;
586 -- ie the ones that occur earliest in the list.
588 sw_tbl :: Array Int SwitchResult
589 sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
593 all_undefined = [ (i, SwBool False) | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
595 defined_elems = map mk_assoc_elem tidied_on_switches
597 -- (avoid some unboxing, bounds checking, and other horrible things:)
598 #if __GLASGOW_HASKELL__ < 405
599 case sw_tbl of { Array bounds_who_needs_'em stuff ->
601 case sw_tbl of { Array _ _ stuff ->
604 case (indexArray# stuff (tagOf_SimplSwitch switch)) of
605 #if __GLASGOW_HASKELL__ < 400
607 #elif __GLASGOW_HASKELL__ < 403
614 mk_assoc_elem k@(MaxSimplifierIterations lvl) = (IBOX(tagOf_SimplSwitch k), SwInt lvl)
615 mk_assoc_elem k@(SimplInlinePhase n) = (IBOX(tagOf_SimplSwitch k), SwInt n)
616 mk_assoc_elem k = (IBOX(tagOf_SimplSwitch k), SwBool True) -- I'm here, Mom!
618 -- cannot have duplicates if we are going to use the array thing
619 rm_dups switches_so_far switch
620 = if switch `is_elem` switches_so_far
622 else switch : switches_so_far
624 sw `is_elem` [] = False
625 sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) _EQ_ (tagOf_SimplSwitch s)
629 Default settings for simplifier switches
632 defaultSimplSwitches = [MaxSimplifierIterations 1]
635 %************************************************************************
637 \subsection{Misc functions for command-line options}
639 %************************************************************************
643 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
645 switchIsOn lookup_fn switch
646 = case (lookup_fn switch) of
647 SwBool False -> False
650 intSwitchSet :: (switch -> SwitchResult)
654 intSwitchSet lookup_fn switch
655 = case (lookup_fn (switch (panic "intSwitchSet"))) of
656 SwInt int -> Just int
661 startsWith :: String -> String -> Maybe String
662 -- startsWith pfx (pfx++rest) = Just rest
664 startsWith [] str = Just str
665 startsWith (c:cs) (s:ss)
666 = if c /= s then Nothing else startsWith cs ss
667 startsWith _ [] = Nothing
669 endsWith :: String -> String -> Maybe String
671 = case (startsWith (reverse cs) (reverse ss)) of
673 Just rs -> Just (reverse rs)