Created
August 16, 2024 14:35
-
-
Save monadplus/853ad5b16058d1e193df31554e15439f to your computer and use it in GitHub Desktop.
Data.Void
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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