Skip to content

Instantly share code, notes, and snippets.

@googleson78
Created October 14, 2020 21:43
Show Gist options
  • Select an option

  • Save googleson78/e670ef118cb3e1238472c9b002fbf5f1 to your computer and use it in GitHub Desktop.

Select an option

Save googleson78/e670ef118cb3e1238472c9b002fbf5f1 to your computer and use it in GitHub Desktop.
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
data Foo = Foo
data Bar = Bar
class OnlyOne ts
instance OnlyOne '[_1]
throwFoo :: OnlyOne (Foo ': ts) => Foo -> IO a
throwFoo = undefined
throwBar :: OnlyOne (Bar ': ts) => Bar -> IO a
throwBar = undefined
thing :: OnlyOne '[Foo, Bar] => IO Int
thing = do
throwBar @'[] Bar
throwFoo @'[Bar] Foo
pure 5
-- > thing
--
-- <interactive>:5:1: error:
-- • No instance for (OnlyOne '[Foo, Bar])
-- arising from a use of ‘thing’
-- • In the expression: thing
-- In an equation for ‘it’: it = thing
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment