ref: f189ccb8ed1a9332fdd145f73ed6cd4339afc4ba
parent: 721bf4750b2c88cdfb361d2b9c4669826862df7f
author: Lennart Augustsson <lennart@augustsson.net>
date: Wed Apr 24 07:50:20 EDT 2024
Refactor
--- a/src/MicroHs/Expr.hs
+++ b/src/MicroHs/Expr.hs
@@ -45,6 +45,7 @@
getArrow, getArrows,
showExprRaw,
mkEStr, mkExn,
+ getAppM,
) where
import Prelude hiding ((<>))
import Control.Arrow(first)
@@ -836,3 +837,9 @@
let str = mkEStr loc $ msg ++ ", at " ++ show loc
fn = ELit loc $ LExn $ "Control.Exception.Internal." ++ exn
in EApp fn str
+
+getAppM :: HasCallStack => EType -> Maybe (Ident, [EType])
+getAppM = loop []
+ where loop as (EVar i) = Just (i, as)
+ loop as (EApp f a) = loop (a:as) f
+ loop _ t = Nothing
--- a/src/MicroHs/TypeCheck.hs
+++ b/src/MicroHs/TypeCheck.hs
@@ -268,10 +268,7 @@
eVarI loc = EVar . mkIdentSLoc loc
getApp :: HasCallStack => EType -> (Ident, [EType])
-getApp = loop []
- where loop as (EVar i) = (i, as)
- loop as (EApp f a) = loop (a:as) f
- loop _ t = impossibleShow t
+getApp t = fromMaybe (impossibleShow t) $ getAppM t
-- Construct a dummy TModule for the currently compiled module.
-- It has all the relevant export tables.
--
⑨