Skip to content

Commit 64d6c5a

Browse files
LiamGoodacrepaf31
authored andcommitted
Instantiate abstraction body during inference (purescript#3128)
1 parent 6a30b56 commit 64d6c5a

2 files changed

Lines changed: 18 additions & 1 deletion

File tree

examples/passing/3125.purs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
module Main where
2+
3+
import Prelude
4+
import Data.Monoid (class Monoid, mempty)
5+
import Control.Monad.Eff.Console (log, logShow)
6+
7+
data B a = B a a
8+
9+
memptyB :: forall a b. Monoid b => B (a -> b)
10+
memptyB = B l r where
11+
l _ = mempty
12+
r _ = mempty
13+
14+
main = do
15+
logShow $ case (memptyB :: B (Int -> Array Unit)) of B l r -> l 0 == r 0
16+
log "Done"

src/Language/PureScript/TypeChecker/Types.hs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -357,7 +357,8 @@ infer' (Abs binder ret)
357357
ty <- freshType
358358
withBindingGroupVisible $ bindLocalVariables [(arg, ty, Defined)] $ do
359359
body@(TypedValue _ _ bodyTy) <- infer' ret
360-
return $ TypedValue True (Abs (VarBinder arg) body) $ function ty bodyTy
360+
(body', bodyTy') <- instantiatePolyTypeWithUnknowns body bodyTy
361+
return $ TypedValue True (Abs (VarBinder arg) body') (function ty bodyTy')
361362
| otherwise = internalError "Binder was not desugared"
362363
infer' (App f arg) = do
363364
f'@(TypedValue _ _ ft) <- infer f

0 commit comments

Comments
 (0)