on master help sign in
fromInteger tweak
fd80612Edwin Brady
src/Idris/ParseExpr.hs+14−1
@@ -576,8 +576,21 @@ app syn = do f <- simpleExpr syn
576 args <- many (do notEndApp; arg syn)
576 args <- many (do notEndApp; arg syn)
577 case args of
577 case args of
578 [] -> return f
578 [] -> return f
579− _ -> return (PApp fc f args))
579+ _ -> return (flattenFromInt fc f args))
580 <?> "function application"
580 <?> "function application"
581+ where
582+ -- bit of a hack to deal with the situation where we're applying a
583+ -- literal to an argument, which we may want for obscure applications
584+ -- of fromInteger, and this will help disambiguate better.
585+ -- We know, at least, it won't be one of the constants!
586+ flattenFromInt fc (PAlternative x alts) args
587+ | Just i <- getFromInt alts
588+ = PApp fc (PRef fc (sUN "fromInteger")) (i : args)
589+ flattenFromInt fc f args = PApp fc f args
590+
591+ getFromInt ((PApp _ (PRef _ n) [a]) : _) | n == sUN "fromInteger" = Just a
592+ getFromInt (_ : xs) = getFromInt xs
593+ getFromInt _ = Nothing
581
594
582{-| Parses a function argument
595{-| Parses a function argument
583@
596@