[project @ 2000-11-13 16:16:05 by sewardj]
[ghc-hetmet.git] / ghc / compiler / main / CmdLineOpts.lhs
1 %
2 % (c) The University of Glasgow, 1996-2000
3 %
4 \section[CmdLineOpts]{Things to do with command-line options}
5
6 \begin{code}
7
8 module CmdLineOpts (
9         CoreToDo(..),
10         SimplifierSwitch(..), isAmongSimpl,
11         StgToDo(..),
12         SwitchResult(..),
13         HscLang(..),
14         DynFlag(..),    -- needed non-abstractly by DriverFlags
15         DynFlags(..),
16
17         v_Static_hsc_opts,
18
19         intSwitchSet,
20         switchIsOn,
21         isStaticHscFlag,
22
23         opt_PprStyle_NoPrags,
24         opt_PprStyle_RawTypes,
25         opt_PprUserLength,
26         opt_PprStyle_Debug,
27
28         dopt,
29
30         -- other dynamic flags
31         dopt_CoreToDo,
32         dopt_StgToDo,
33         dopt_HscLang,
34         dopt_OutName,
35
36         -- profiling opts
37         opt_AutoSccsOnAllToplevs,
38         opt_AutoSccsOnExportedToplevs,
39         opt_AutoSccsOnIndividualCafs,
40         opt_AutoSccsOnDicts,
41         opt_SccProfilingOn,
42         opt_DoTickyProfiling,
43
44         -- language opts
45         opt_AllStrict,
46         opt_DictsStrict,
47         opt_MaxContextReductionDepth,
48         opt_IrrefutableTuples,
49         opt_NumbersStrict,
50         opt_Parallel,
51         opt_SMP,
52
53         -- optimisation opts
54         opt_DoSemiTagging,
55         opt_FoldrBuildOn,
56         opt_LiberateCaseThreshold,
57         opt_StgDoLetNoEscapes,
58         opt_UnfoldCasms,
59         opt_UsageSPOn,
60         opt_UnboxStrictFields,
61         opt_SimplNoPreInlining,
62         opt_SimplDoEtaReduction,
63         opt_SimplDoLambdaEtaExpansion,
64         opt_SimplCaseOfCase,
65         opt_SimplCaseMerge,
66         opt_SimplPedanticBottoms,
67         opt_SimplExcessPrecision,
68
69         -- Unfolding control
70         opt_UF_HiFileThreshold,
71         opt_UF_CreationThreshold,
72         opt_UF_UseThreshold,
73         opt_UF_FunAppDiscount,
74         opt_UF_KeenessFactor,
75         opt_UF_UpdateInPlace,
76         opt_UF_CheapOp,
77         opt_UF_DearOp,
78
79         -- misc opts
80         opt_InPackage,
81         opt_EmitCExternDecls,
82         opt_EnsureSplittableC,
83         opt_GranMacros,
84         opt_HiVersion,
85         opt_HistorySize,
86         opt_IgnoreAsserts,
87         opt_IgnoreIfacePragmas,
88         opt_NoHiCheck,
89         opt_OmitBlackHoling,
90         opt_OmitInterfacePragmas,
91         opt_NoPruneTyDecls,
92         opt_NoPruneDecls,
93         opt_Static,
94         opt_Unregisterised,
95         opt_Verbose
96     ) where
97
98 #include "HsVersions.h"
99
100 import Array    ( array, (//) )
101 import GlaExts
102 import IOExts   ( IORef, readIORef )
103 import Constants        -- Default values for some flags
104 import Util
105 import FastTypes
106
107 import Maybes           ( firstJust )
108 import Panic            ( panic )
109
110 #if __GLASGOW_HASKELL__ < 301
111 import ArrBase  ( Array(..) )
112 #else
113 import PrelArr  ( Array(..) )
114 #endif
115 \end{code}
116
117 %************************************************************************
118 %*                                                                      *
119 \subsection{Command-line options}
120 %*                                                                      *
121 %************************************************************************
122
123 The hsc command-line options are split into two categories:
124
125   - static flags
126   - dynamic flags
127
128 Static flags are represented by top-level values of type Bool or Int,
129 for example.  They therefore have the same value throughout the
130 invocation of hsc.
131
132 Dynamic flags are represented by an abstract type, DynFlags, which is
133 passed into hsc by the compilation manager for every compilation.
134 Dynamic flags are those that change on a per-compilation basis,
135 perhaps because they may be present in the OPTIONS pragma at the top
136 of a module.
137
138 Other flag-related blurb:
139
140 A list of {\em ToDo}s is things to be done in a particular part of
141 processing.  A (fictitious) example for the Core-to-Core simplifier
142 might be: run the simplifier, then run the strictness analyser, then
143 run the simplifier again (three ``todos'').
144
145 There are three ``to-do processing centers'' at the moment.  In the
146 main loop (\tr{main/Main.lhs}), in the Core-to-Core processing loop
147 (\tr{simplCore/SimplCore.lhs), and in the STG-to-STG processing loop
148 (\tr{simplStg/SimplStg.lhs}).
149
150 %************************************************************************
151 %*                                                                      *
152 \subsection{Datatypes associated with command-line options}
153 %*                                                                      *
154 %************************************************************************
155
156 \begin{code}
157 data SwitchResult
158   = SwBool      Bool            -- on/off
159   | SwString    FAST_STRING     -- nothing or a String
160   | SwInt       Int             -- nothing or an Int
161 \end{code}
162
163 \begin{code}
164 data CoreToDo           -- These are diff core-to-core passes,
165                         -- which may be invoked in any order,
166                         -- as many times as you like.
167
168   = CoreDoSimplify      -- The core-to-core simplifier.
169         (SimplifierSwitch -> SwitchResult)
170                         -- Each run of the simplifier can take a different
171                         -- set of simplifier-specific flags.
172   | CoreDoFloatInwards
173   | CoreDoFloatOutwards Bool    -- True <=> float lambdas to top level
174   | CoreLiberateCase
175   | CoreDoPrintCore
176   | CoreDoStaticArgs
177   | CoreDoStrictness
178   | CoreDoWorkerWrapper
179   | CoreDoSpecialising
180   | CoreDoUSPInf
181   | CoreDoCPResult
182   | CoreDoGlomBinds
183   | CoreCSE
184
185   | CoreDoNothing        -- useful when building up lists of these things
186 \end{code}
187
188 \begin{code}
189 data StgToDo
190   = StgDoStaticArgs
191   | StgDoLambdaLift
192   | StgDoMassageForProfiling  -- should be (next to) last
193   -- There's also setStgVarInfo, but its absolute "lastness"
194   -- is so critical that it is hardwired in (no flag).
195   | D_stg_stats
196 \end{code}
197
198 \begin{code}
199 data SimplifierSwitch
200   = MaxSimplifierIterations Int
201   | SimplInlinePhase Int
202   | DontApplyRules
203   | NoCaseOfCase
204   | SimplLetToCase
205 \end{code}
206
207 %************************************************************************
208 %*                                                                      *
209 \subsection{Dynamic command-line options}
210 %*                                                                      *
211 %************************************************************************
212
213 \begin{code}
214 data DynFlag
215
216    -- debugging flags
217    = Opt_D_dump_all
218    | Opt_D_dump_most
219    | Opt_D_dump_absC
220    | Opt_D_dump_asm
221    | Opt_D_dump_cpranal
222    | Opt_D_dump_deriv
223    | Opt_D_dump_ds
224    | Opt_D_dump_flatC
225    | Opt_D_dump_foreign
226    | Opt_D_dump_inlinings
227    | Opt_D_dump_occur_anal
228    | Opt_D_dump_parsed
229    | Opt_D_dump_realC
230    | Opt_D_dump_rn
231    | Opt_D_dump_simpl
232    | Opt_D_dump_simpl_iterations
233    | Opt_D_dump_spec
234    | Opt_D_dump_stg
235    | Opt_D_dump_stranal
236    | Opt_D_dump_tc
237    | Opt_D_dump_types
238    | Opt_D_dump_rules
239    | Opt_D_dump_usagesp
240    | Opt_D_dump_cse
241    | Opt_D_dump_worker_wrapper
242    | Opt_D_show_passes
243    | Opt_D_dump_rn_trace
244    | Opt_D_dump_rn_stats
245    | Opt_D_dump_stix
246    | Opt_D_dump_simpl_stats
247    | Opt_D_source_stats
248    | Opt_D_verbose_core2core
249    | Opt_D_verbose_stg2stg
250    | Opt_D_dump_hi
251    | Opt_D_dump_hi_diffs
252    | Opt_D_dump_minimal_imports
253    | Opt_DoCoreLinting
254    | Opt_DoStgLinting
255    | Opt_DoUSPLinting
256
257    | Opt_WarnDuplicateExports
258    | Opt_WarnHiShadows
259    | Opt_WarnIncompletePatterns
260    | Opt_WarnMissingFields
261    | Opt_WarnMissingMethods
262    | Opt_WarnMissingSigs
263    | Opt_WarnNameShadowing
264    | Opt_WarnOverlappingPatterns
265    | Opt_WarnSimplePatterns
266    | Opt_WarnTypeDefaults
267    | Opt_WarnUnusedBinds
268    | Opt_WarnUnusedImports
269    | Opt_WarnUnusedMatches
270    | Opt_WarnDeprecations
271
272    -- language opts
273    | Opt_AllowOverlappingInstances
274    | Opt_AllowUndecidableInstances
275    | Opt_GlasgowExts
276    | Opt_Generics
277    | Opt_NoImplicitPrelude 
278
279    -- misc
280    | Opt_ReportCompile
281    deriving (Eq)
282
283 data DynFlags = DynFlags {
284   coreToDo   :: [CoreToDo],
285   stgToDo    :: [StgToDo],
286   hscLang    :: HscLang,
287   hscOutName :: String,  -- name of the file in which to place output
288   flags      :: [DynFlag]
289  }
290
291 dopt :: DynFlag -> DynFlags -> Bool
292 dopt f dflags  = f `elem` (flags dflags)
293
294 dopt_CoreToDo :: DynFlags -> [CoreToDo]
295 dopt_CoreToDo = coreToDo
296
297 dopt_StgToDo :: DynFlags -> [StgToDo]
298 dopt_StgToDo = stgToDo
299
300 dopt_OutName :: DynFlags -> String
301 dopt_OutName = hscOutName
302
303 data HscLang
304   = HscC
305   | HscAsm
306   | HscJava
307   | HscInterpreted
308     deriving Eq
309
310 dopt_HscLang :: DynFlags -> HscLang
311 dopt_HscLang = hscLang
312 \end{code}
313
314 %************************************************************************
315 %*                                                                      *
316 \subsection{Classifying command-line options}
317 %*                                                                      *
318 %************************************************************************
319
320 \begin{code}
321 -- v_Statis_hsc_opts is here to avoid a circular dependency with
322 -- main/DriverState.
323 GLOBAL_VAR(v_Static_hsc_opts, [], [String])
324
325 lookUp           :: FAST_STRING -> Bool
326 lookup_int       :: String -> Maybe Int
327 lookup_def_int   :: String -> Int -> Int
328 lookup_def_float :: String -> Float -> Float
329 lookup_str       :: String -> Maybe String
330
331 unpacked_static_opts = unsafePerformIO (readIORef v_Static_hsc_opts)
332 packed_static_opts   = map _PK_ unpacked_static_opts
333
334 lookUp     sw = sw `elem` packed_static_opts
335         
336 lookup_str sw = firstJust (map (startsWith sw) unpacked_static_opts)
337
338 lookup_int sw = case (lookup_str sw) of
339                   Nothing -> Nothing
340                   Just xx -> Just (read xx)
341
342 lookup_def_int sw def = case (lookup_str sw) of
343                             Nothing -> def              -- Use default
344                             Just xx -> read xx
345
346 lookup_def_float sw def = case (lookup_str sw) of
347                             Nothing -> def              -- Use default
348                             Just xx -> read xx
349
350
351 {-
352  Putting the compiler options into temporary at-files
353  may turn out to be necessary later on if we turn hsc into
354  a pure Win32 application where I think there's a command-line
355  length limit of 255. unpacked_opts understands the @ option.
356
357 unpacked_opts :: [String]
358 unpacked_opts =
359   concat $
360   map (expandAts) $
361   map _UNPK_ argv  -- NOT ARGV any more: v_Static_hsc_opts
362   where
363    expandAts ('@':fname) = words (unsafePerformIO (readFile fname))
364    expandAts l = [l]
365 -}
366 \end{code}
367
368 %************************************************************************
369 %*                                                                      *
370 \subsection{Static options}
371 %*                                                                      *
372 %************************************************************************
373
374 \begin{code}
375 -- debugging opts
376 opt_PprStyle_NoPrags            = lookUp  SLIT("-dppr-noprags")
377 opt_PprStyle_Debug              = lookUp  SLIT("-dppr-debug")
378 opt_PprStyle_RawTypes           = lookUp  SLIT("-dppr-rawtypes")
379 opt_PprUserLength               = lookup_def_int "-dppr-user-length" 5 --ToDo: give this a name
380
381 -- profiling opts
382 opt_AutoSccsOnAllToplevs        = lookUp  SLIT("-fauto-sccs-on-all-toplevs")
383 opt_AutoSccsOnExportedToplevs   = lookUp  SLIT("-fauto-sccs-on-exported-toplevs")
384 opt_AutoSccsOnIndividualCafs    = lookUp  SLIT("-fauto-sccs-on-individual-cafs")
385 opt_AutoSccsOnDicts             = lookUp  SLIT("-fauto-sccs-on-dicts")
386 opt_SccProfilingOn              = lookUp  SLIT("-fscc-profiling")
387 opt_DoTickyProfiling            = lookUp  SLIT("-fticky-ticky")
388
389 -- language opts
390 opt_AllStrict                   = lookUp  SLIT("-fall-strict")
391 opt_DictsStrict                 = lookUp  SLIT("-fdicts-strict")
392 opt_IrrefutableTuples           = lookUp  SLIT("-firrefutable-tuples")
393 opt_MaxContextReductionDepth    = lookup_def_int "-fcontext-stack" mAX_CONTEXT_REDUCTION_DEPTH
394 opt_NumbersStrict               = lookUp  SLIT("-fnumbers-strict")
395 opt_Parallel                    = lookUp  SLIT("-fparallel")
396 opt_SMP                         = lookUp  SLIT("-fsmp")
397
398 -- optimisation opts
399 opt_DoSemiTagging               = lookUp  SLIT("-fsemi-tagging")
400 opt_FoldrBuildOn                = lookUp  SLIT("-ffoldr-build-on")
401 opt_LiberateCaseThreshold       = lookup_def_int "-fliberate-case-threshold" (10::Int)
402 opt_StgDoLetNoEscapes           = lookUp  SLIT("-flet-no-escape")
403 opt_UnfoldCasms                 = lookUp SLIT("-funfold-casms-in-hi-file")
404 opt_UsageSPOn                   = lookUp  SLIT("-fusagesp-on")
405 opt_UnboxStrictFields           = lookUp  SLIT("-funbox-strict-fields")
406
407 {-
408    The optional '-inpackage=P' flag tells what package
409    we are compiling this module for.
410    The Prelude, for example is compiled with '-package prelude'
411 -}
412 opt_InPackage                   = case lookup_str "-inpackage=" of
413                                     Just p  -> _PK_ p
414                                     Nothing -> SLIT("Main")     -- The package name if none is specified
415
416 opt_EmitCExternDecls            = lookUp  SLIT("-femit-extern-decls")
417 opt_EnsureSplittableC           = lookUp  SLIT("-fglobalise-toplev-names")
418 opt_GranMacros                  = lookUp  SLIT("-fgransim")
419 opt_HiVersion                   = lookup_def_int "-fhi-version=" 0 -- what version we're compiling.
420 opt_HistorySize                 = lookup_def_int "-fhistory-size" 20
421 opt_IgnoreAsserts               = lookUp  SLIT("-fignore-asserts")
422 opt_IgnoreIfacePragmas          = lookUp  SLIT("-fignore-interface-pragmas")
423 opt_NoHiCheck                   = lookUp  SLIT("-fno-hi-version-check")
424 opt_OmitBlackHoling             = lookUp  SLIT("-dno-black-holing")
425 opt_OmitInterfacePragmas        = lookUp  SLIT("-fomit-interface-pragmas")
426
427 -- Simplifier switches
428 opt_SimplNoPreInlining          = lookUp SLIT("-fno-pre-inlining")
429         -- NoPreInlining is there just to see how bad things
430         -- get if you don't do it!
431 opt_SimplDoEtaReduction         = lookUp SLIT("-fdo-eta-reduction")
432 opt_SimplDoLambdaEtaExpansion   = lookUp SLIT("-fdo-lambda-eta-expansion")
433 opt_SimplCaseOfCase             = lookUp SLIT("-fcase-of-case")
434 opt_SimplCaseMerge              = lookUp SLIT("-fcase-merge")
435 opt_SimplPedanticBottoms        = lookUp SLIT("-fpedantic-bottoms")
436 opt_SimplExcessPrecision        = lookUp SLIT("-fexcess-precision")
437
438 -- Unfolding control
439 opt_UF_HiFileThreshold          = lookup_def_int "-funfolding-interface-threshold" (45::Int)
440 opt_UF_CreationThreshold        = lookup_def_int "-funfolding-creation-threshold"  (45::Int)
441 opt_UF_UseThreshold             = lookup_def_int "-funfolding-use-threshold"       (8::Int)     -- Discounts can be big
442 opt_UF_FunAppDiscount           = lookup_def_int "-funfolding-fun-discount"        (6::Int)     -- It's great to inline a fn
443 opt_UF_KeenessFactor            = lookup_def_float "-funfolding-keeness-factor"    (1.5::Float)
444 opt_UF_UpdateInPlace            = lookUp  SLIT("-funfolding-update-in-place")
445
446 opt_UF_CheapOp  = ( 1 :: Int)   -- Only one instruction; and the args are charged for
447 opt_UF_DearOp   = ( 4 :: Int)
448                         
449 opt_NoPruneDecls                = lookUp SLIT("-fno-prune-decls")
450 opt_NoPruneTyDecls              = lookUp SLIT("-fno-prune-tydecls")
451 opt_Static                      = lookUp SLIT("-static")
452 opt_Unregisterised              = lookUp SLIT("-funregisterised")
453 opt_Verbose                     = lookUp SLIT("-v")
454 \end{code}
455
456 %************************************************************************
457 %*                                                                      *
458 \subsection{List of static hsc flags}
459 %*                                                                      *
460 %************************************************************************
461
462 \begin{code}
463 isStaticHscFlag f =
464   f `elem` [
465         "fauto-sccs-on-all-toplevs",
466         "fauto-sccs-on-exported-toplevs",
467         "fauto-sccs-on-individual-cafs",
468         "fauto-sccs-on-dicts",
469         "fscc-profiling",
470         "fticky-ticky",
471         "fall-strict",
472         "fdicts-strict",
473         "firrefutable-tuples",
474         "fnumbers-strict",
475         "fparallel",
476         "fsmp",
477         "fsemi-tagging",
478         "ffoldr-build-on",
479         "flet-no-escape",
480         "funfold-casms-in-hi-file",
481         "fusagesp-on",
482         "funbox-strict-fields",
483         "femit-extern-decls",
484         "fglobalise-toplev-names",
485         "fgransim",
486         "fignore-asserts",
487         "fignore-interface-pragmas",
488         "fno-hi-version-check",
489         "fno-implicit-prelude",
490         "dno-black-holing",
491         "fomit-interface-pragmas",
492         "fno-pre-inlining",
493         "fdo-eta-reduction",
494         "fdo-lambda-eta-expansion",
495         "fcase-of-case",
496         "fcase-merge",
497         "fpedantic-bottoms",
498         "fexcess-precision",
499         "funfolding-update-in-place",
500         "freport-compile",
501         "fno-prune-decls",
502         "fno-prune-tydecls",
503         "static",
504         "funregisterised",
505         "v" ]
506   || any (flip prefixMatch f) [
507         "fcontext-stack",
508         "fliberate-case-threshold",
509         "fhi-version=",
510         "fhistory-size",
511         "funfolding-interface-threshold",
512         "funfolding-creation-threshold",
513         "funfolding-use-threshold",
514         "funfolding-fun-discount",
515         "funfolding-keeness-factor"
516      ]
517 \end{code}
518
519 %************************************************************************
520 %*                                                                      *
521 \subsection{Switch ordering}
522 %*                                                                      *
523 %************************************************************************
524
525 These things behave just like enumeration types.
526
527 \begin{code}
528 instance Eq SimplifierSwitch where
529     a == b = tagOf_SimplSwitch a ==# tagOf_SimplSwitch b
530
531 instance Ord SimplifierSwitch where
532     a <  b  = tagOf_SimplSwitch a <# tagOf_SimplSwitch b
533     a <= b  = tagOf_SimplSwitch a <=# tagOf_SimplSwitch b
534
535
536 tagOf_SimplSwitch (SimplInlinePhase _)          = _ILIT(1)
537 tagOf_SimplSwitch (MaxSimplifierIterations _)   = _ILIT(2)
538 tagOf_SimplSwitch DontApplyRules                = _ILIT(3)
539 tagOf_SimplSwitch SimplLetToCase                = _ILIT(4)
540 tagOf_SimplSwitch NoCaseOfCase                  = _ILIT(5)
541
542 -- If you add anything here, be sure to change lAST_SIMPL_SWITCH_TAG, too!
543
544 lAST_SIMPL_SWITCH_TAG = 5
545 \end{code}
546
547 %************************************************************************
548 %*                                                                      *
549 \subsection{Switch lookup}
550 %*                                                                      *
551 %************************************************************************
552
553 \begin{code}
554 isAmongSimpl :: [SimplifierSwitch] -> SimplifierSwitch -> SwitchResult
555 isAmongSimpl on_switches                -- Switches mentioned later occur *earlier*
556                                         -- in the list; defaults right at the end.
557   = let
558         tidied_on_switches = foldl rm_dups [] on_switches
559                 -- The fold*l* ensures that we keep the latest switches;
560                 -- ie the ones that occur earliest in the list.
561
562         sw_tbl :: Array Int SwitchResult
563         sw_tbl = (array (0, lAST_SIMPL_SWITCH_TAG) -- bounds...
564                         all_undefined)
565                  // defined_elems
566
567         all_undefined = [ (i, SwBool False) | i <- [0 .. lAST_SIMPL_SWITCH_TAG ] ]
568
569         defined_elems = map mk_assoc_elem tidied_on_switches
570     in
571     -- (avoid some unboxing, bounds checking, and other horrible things:)
572 #if __GLASGOW_HASKELL__ < 405
573     case sw_tbl of { Array bounds_who_needs_'em stuff ->
574 #else
575     case sw_tbl of { Array _ _ stuff ->
576 #endif
577     \ switch ->
578         case (indexArray# stuff (tagOf_SimplSwitch switch)) of
579 #if __GLASGOW_HASKELL__ < 400
580           Lift v -> v
581 #elif __GLASGOW_HASKELL__ < 403
582           (# _, v #) -> v
583 #else
584           (# v #) -> v
585 #endif
586     }
587   where
588     mk_assoc_elem k@(MaxSimplifierIterations lvl)
589         = (iBox (tagOf_SimplSwitch k), SwInt lvl)
590     mk_assoc_elem k@(SimplInlinePhase n)
591         = (iBox (tagOf_SimplSwitch k), SwInt n)
592     mk_assoc_elem k
593         = (iBox (tagOf_SimplSwitch k), SwBool True) -- I'm here, Mom!
594
595     -- cannot have duplicates if we are going to use the array thing
596     rm_dups switches_so_far switch
597       = if switch `is_elem` switches_so_far
598         then switches_so_far
599         else switch : switches_so_far
600       where
601         sw `is_elem` []     = False
602         sw `is_elem` (s:ss) = (tagOf_SimplSwitch sw) ==# (tagOf_SimplSwitch s)
603                             || sw `is_elem` ss
604 \end{code}
605
606
607 %************************************************************************
608 %*                                                                      *
609 \subsection{Misc functions for command-line options}
610 %*                                                                      *
611 %************************************************************************
612
613
614 \begin{code}
615 switchIsOn :: (switch -> SwitchResult) -> switch -> Bool
616
617 switchIsOn lookup_fn switch
618   = case (lookup_fn switch) of
619       SwBool False -> False
620       _            -> True
621
622 intSwitchSet :: (switch -> SwitchResult)
623              -> (Int -> switch)
624              -> Maybe Int
625
626 intSwitchSet lookup_fn switch
627   = case (lookup_fn (switch (panic "intSwitchSet"))) of
628       SwInt int -> Just int
629       _         -> Nothing
630 \end{code}
631
632 \begin{code}
633 startsWith :: String -> String -> Maybe String
634 -- startsWith pfx (pfx++rest) = Just rest
635
636 startsWith []     str = Just str
637 startsWith (c:cs) (s:ss)
638   = if c /= s then Nothing else startsWith cs ss
639 startsWith  _     []  = Nothing
640
641 endsWith  :: String -> String -> Maybe String
642 endsWith cs ss
643   = case (startsWith (reverse cs) (reverse ss)) of
644       Nothing -> Nothing
645       Just rs -> Just (reverse rs)
646 \end{code}