Commit 70834744 authored by simonpj's avatar simonpj
Browse files

[project @ 2005-10-14 11:23:46 by simonpj]

add some record-syntax stuff
parent a0934074
......@@ -24,3 +24,6 @@ test('tc', normal, compile_and_run, [''])
test('arrow', normal, compile, [''])
test('tdpe', normal, compile, [''])
test('Nilsson', normal, compile, [''])
test('records', normal, compile_and_run, [''])
test('records-fail1', normal, compile_fail, [''])
{-# OPTIONS -fglasgow-exts #-}
-- Tests record syntax for GADTs
module ShouldFail where
data T a where
T1 { x :: a, y :: b } :: T (a,b)
T4 { x :: Int } :: T [a]
\ No newline at end of file
records-fail1.hs:7:0:
Constructors T1 and T4 have a common field `x',
but have different result types
In the data type declaration for `T'
{-# OPTIONS -fglasgow-exts #-}
-- Tests record syntax for GADTs
module Main where
data T a where
T1 { x :: a, y :: b } :: T (a,b)
T2 { x :: a } :: T (a,b)
T3 { z :: Int } :: T Bool
f xv yv = T1 { x = xv, y = yv }
g :: T a -> T a
g (T1 {x=xv, y=yv}) = T2 { x = xv }
-- h :: Num a => T a any -> a
h v = x v + 1
main = do { let t1 = T1 { y = "foo", x = 4 }
t2 = g t1
; print (h (f 8 undefined))
; print (h t2)
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment