Skip to content

Record patterns in do binds do not need MonadFail when they cannot fail - #525

Merged
augustss merged 1 commit into
augustss:masterfrom
haskell-miso:record-pattern-bind
Sep 29, 2026
Merged

augustss merged 1 commit into
augustss:masterfrom
haskell-miso:record-pattern-bind

Conversation

@dmjio

@dmjio dmjio commented Sep 28, 2026

Copy link
Copy Markdown
Contributor

This PR should be low-hanging fruit discovered in dmjio/miso#1663.

A record pattern in a 'do' bind was always treated as one that can fail, so it required MonadFail even for a single-constructor type with irrefutable field patterns:

    newtype M a = M a            -- Functor, Applicative, Monad; no MonadFail
    data R = R { x :: Int, y :: Int }
    sumR mr = do
      R { x = a, y = b } <- mr
      return (a + b)
RecordBind.hs: line 21, col 3: Cannot satisfy constraint: MonadFail M

failureFree had no case for record patterns (EUpdate) and fell through to "can fail". It now treats C { f = p, .. } like the positional pattern: failure free when the constructor is the only one and every field pattern is; puns and '..' bind variables, so they are.

Found while compiling miso, which uses such binds.

A record pattern in a 'do' bind was always treated as one that can
fail, so it required MonadFail even for a single-constructor type with
irrefutable field patterns:

    newtype M a = M a            -- Functor, Applicative, Monad; no MonadFail
    data R = R { x :: Int, y :: Int }
    sumR mr = do
      R { x = a, y = b } <- mr
      return (a + b)

    RecordBind.hs: line 21, col 3: Cannot satisfy constraint: MonadFail M

failureFree had no case for record patterns (EUpdate) and fell through
to "can fail".  It now treats C { f = p, .. } like the positional
pattern: failure free when the constructor is the only one and every
field pattern is; puns and '..' bind variables, so they are.

Found while compiling miso, which uses such binds.
@augustss
augustss merged commit 683e9fd into augustss:master Sep 29, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants