S. Alexander Jacobson <[EMAIL PROTECTED]> writes:
>
> I am trying to get Malcolm Wallace's Xtract code to run with
> Hugs and have noticed a few inconsistencies between whatever
> compiler he is using and hugs...
>
Great - I'd encourage others to share their experiences of trying to
work with multiple Haskell systems. Cross-system portability
& Report compliance is not something that's at the very top of a
Haskell system implementor's checklist (i.e., give them a helping hand.)
>
> 2. Allowing use of qualified names without importing qualified
> MW's compiler allows use of Prelude.elem without qualified import of
> the prelude. Hugs does not like that. I think Hugs is
> right, but I am not sure which is "correct".
>
NHC is right, but using left-of-centre features of the module system
is not something I would recommend if you want your code to work
with Hugs.
>
> 3. Inadequacy of Haskell
> There are a few places where MW relies on the preprocessor rather than
> Haskell. Xtract has this code:
> ---------From ParseSTXml.hs--------
> #define PARSEARG(tok) P (\st inp -> case inp of { \
> ((p,tok n):ts) -> [(n,st,ts)]; \
> ts -> [] } )
> name :: Parser SymTab Token Name
> name = PARSEARG(TokName)
>
> string, freetext :: Parser SymTab Token String
> string = PARSEARG(TokName)
> freetext = PARSEARG(TokFreeText)
> -------
> Is there clean a way of achieving the same functionality
> without relying on the preprocessor?
>
Your mileage may vary, but I'd probably do something like
this here:
mbParse :: (tok -> Maybe a) -> Parser state tok a
mbParse matcher = P $ \ st inp ->
case inp of
((_,tok):ts) | Maybe.isJust mb_v -> [(v, st, ts)]
where
mb_v = matcher tok
(Just v) = mb_v
_ -> []
name = mbParse deTok where deTok (TokName x) = Just x ; deTok _ =
Nothing
freetext = mbParse deTok where deTok (TokFreeText x) = Just x ; deTok _ =
Nothing
string = name
If H98 had pattern guards, mbParse could have been expressed
with less effort,
mbParse matcher = P $ \ st inp ->
case inp of
((_,tok):ts) | (Just v) <- matcher tok -> [(v,st,ts)]
_ -> []
--sigbjorn
RE: Xtract with hugs and Haskell implementation inconsistency
Sigbjorn Finne (Intl Vendor) Thu, 30 Sep 1999 03:12:24 -0700
- Xtract with hugs and Haskell implementation i... S. Alexander Jacobson
- Re: Xtract with hugs and Haskell impleme... Sigbjorn Finne (Intl Vendor)
- Re: Xtract with hugs and Haskell impleme... Andy Gill
- Re: Xtract with hugs and Haskell impleme... Malcolm Wallace
