Skip to content

Instantly share code, notes, and snippets.

@maoe
Forked from cutsea110/Test2.hs
Created July 26, 2012 10:39
Show Gist options
  • Save maoe/3181426 to your computer and use it in GitHub Desktop.
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")ではデータ構築可能
{-# 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