Skip to content

Instantly share code, notes, and snippets.

@tfausak

tfausak/Main.hs

Created Apr 30, 2021
Embed
What would you like to do?
Example of unexpected ambiguity. https://github.com/tfausak/witch/issues/19
#! /usr/bin/env stack
-- stack --resolver ghc-9.0.1 script
{-# language AllowAmbiguousTypes #-}
{-# language ScopedTypeVariables #-}
{-# language TypeApplications #-}
{-# language TypeFamilies #-}
data Break
type family Ambiguous a where
Ambiguous Break = ()
Ambiguous a = a
as :: forall a b . Ambiguous a ~ b => b -> b
as = id
identity :: forall a . a -> a
identity = as @a
{-
• Couldn't match type ‘a’ with ‘Ambiguous a’
arising from a use of ‘as’
‘a’ is a rigid type variable bound by
the type signature for:
identity :: forall a. a -> a
at /tmp/tmp.vkOEgTlyHU/Main.hs:17:1-29
• In the expression: as @a
In an equation for ‘identity’: identity = as @a
• Relevant bindings include
identity :: a -> a (bound at /tmp/tmp.vkOEgTlyHU/Main.hs:18:1)
-}
main :: IO ()
main = pure $ identity ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment