-
-
Save maoe/3181426 to your computer and use it in GitHub Desktop.
:t zがダメだけど、D (X "123") 123 (1::Y)やD (X "123") 123 (X "456")ではデータ構築可能
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 TypeSynonymInstances #-} | |
{-# LANGUAGE RankNTypes #-} | |
{-# LANGUAGE ExistentialQuantification #-} | |
{-# LANGUAGE GADTs #-} | |
module Test where | |
data X = X String | |
deriving Show | |
type Y = Int | |
class Z a where | |
instance Z X | |
instance Z Y | |
data D = forall a. (Show a, Z a) => D { x :: X | |
, y :: Y | |
, z :: a | |
} | |
{- GHCでは使えないけど、これと同じ。 | |
data D = D { x :: X | |
, y :: Y | |
, z :: exists a. (Show a, Z a) => a | |
} | |
-} | |
test = case D (X "Hello") 123 (456 :: Y) of | |
D x y z -> print z |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment