diff --git a/src/Language/Syntactic/Sharing/SimpleCodeMotion.hs b/src/Language/Syntactic/Sharing/SimpleCodeMotion.hs
--- a/src/Language/Syntactic/Sharing/SimpleCodeMotion.hs
+++ b/src/Language/Syntactic/Sharing/SimpleCodeMotion.hs
@@ -134,9 +134,9 @@
 
     chooseEnv :: Env dom -> ASTF dom b -> Maybe (Chosen dom a)
     chooseEnv env b
-        | liftable pd env b = do
-            id <- mkId b a
-            return $ Chosen id b
+        | liftable pd env b
+        , Just id <- mkId b a
+        = Just $ Chosen id b
     chooseEnv env b = chooseEnvSub env b
 
     -- | Like 'chooseEnv', but does not consider the top expression for sharing
diff --git a/syntactic.cabal b/syntactic.cabal
--- a/syntactic.cabal
+++ b/syntactic.cabal
@@ -1,5 +1,5 @@
 Name:           syntactic
-Version:        1.5.1
+Version:        1.5.2
 Synopsis:       Generic abstract syntax, and utilities for embedded languages
 Description:    This library provides:
                 .
