Created
October 14, 2020 21:43
-
-
Save googleson78/e670ef118cb3e1238472c9b002fbf5f1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 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