Skip to content

Instantly share code, notes, and snippets.

@monadplus
Created August 16, 2024 14:35
Show Gist options
  • Save monadplus/853ad5b16058d1e193df31554e15439f to your computer and use it in GitHub Desktop.
Save monadplus/853ad5b16058d1e193df31554e15439f to your computer and use it in GitHub Desktop.
Data.Void
{-# LANGUAGE BangPatterns #-}
module Main where
import Data.Void
-- We still need to pattern-match against Left because
-- laziness allows that branch to still be valid even if Void is unhabited
-- i.e. it could still be populated by bottom values.
f :: Either Void Int -> Int
f (Right x) = x
f (Left void) = absurd void
-- But if we help the strictness analysis a bit
data Either' e a = Left' !e | Right' a
-- GHC can discard the branch
f' :: Either' Void Int -> Int
f' (Right' x) = x
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment