Created
November 16, 2022 09:33
-
-
Save igrep/72908d8be0ad5cfe1fd62ef4838b3955 to your computer and use it in GitHub Desktop.
Example type class for a type-level list with no instance for an empty list.
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 DataKinds #-} | |
{-# LANGUAGE FlexibleInstances #-} | |
{-# LANGUAGE KindSignatures #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
{-# LANGUAGE TypeApplications #-} | |
{-# LANGUAGE TypeOperators #-} | |
import Data.Kind (Type) | |
data ExampleData (as :: [Type]) = ExampleData | |
class ExampleClass (as :: [Type]) where | |
example :: ExampleData as -> String | |
instance {-# OVERLAPPING #-} ExampleClass '[a] where | |
example _ = "one" | |
instance ExampleClass as => ExampleClass (a ': as) where | |
example _ = "two or more, " ++ example (ExampleData @as) | |
main = putStrLn $ example (ExampleData @'[Char, Int, Bool]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment