Last active
December 29, 2021 11:53
-
-
Save joncol/50461ec618fe1fb7b7245c5d7869e3ed to your computer and use it in GitHub Desktop.
GADTs example
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 DataKinds #-} | |
{-# LANGUAGE GADTs #-} | |
{-# LANGUAGE LambdaCase #-} | |
{-# LANGUAGE PolyKinds #-} | |
{-# LANGUAGE RankNTypes #-} | |
module GADTs where | |
data Subject = Math | English | French | |
deriving (Eq, Show) | |
class MathOrEnglish (a :: Subject) | |
instance MathOrEnglish 'Math | |
instance MathOrEnglish 'English | |
data User a where | |
Teacher :: Subject -> User a | |
-- Uncommenting line 25 below gives the error: | |
-- • Expected a type, but ‘a’ has kind ‘Subject’ | |
-- • In the type ‘a’ | |
-- In the definition of data constructor ‘Student’ | |
-- In the data declaration for ‘User’ (lsp) | |
-- Student :: (MathOrEnglish a) => a -> User a -- doesn't work | |
Student :: (Eq a) => a -> User a -- works |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment