-- Class Declarations class {- variant -} List xs x => List2 xs x | xs -> x where { cons2 :: x -> x -> xs -> xs; }; class {- variant -} List xs x => AppendList xs x | xs -> x where { append :: xs -> xs -> xs; }; class {- variant -} List xs x | xs -> x where { cons :: x -> xs -> xs; nil :: xs; }; class {- record -} ListAcceptor xs x | xs -> x where { toListView :: xs -> Either (x, xs) (); }; -- Data Declarations data Data''1 a = C''cons''1 a (Data''1 a) | C''nil''1 | C''append''1 (Data''1 a) (Data''1 a) | C''cons2''1 a a (Data''1 a) ; {- -- using GADT-style declaration data Data''1 a where { C''cons''1 :: a -> Data''1 a -> Data''1 a; C''nil''1 :: Data''1 a; C''append''1 :: Data''1 a -> Data''1 a -> Data''1 a; C''cons2''1 :: a -> a -> Data''1 a -> Data''1 a; }; -} data Data''0 a = C''cons''0 a (Data''0 a) | C''nil''0 | C''append''0 (Data''0 a) (Data''0 a) | C''cons2''0 a a (Data''0 a) ; {- -- using GADT-style declaration data Data''0 a where { C''cons''0 :: a -> Data''0 a -> Data''0 a; C''nil''0 :: Data''0 a; C''append''0 :: Data''0 a -> Data''0 a -> Data''0 a; C''cons2''0 :: a -> a -> Data''0 a -> Data''0 a; }; -} -- Instance Declarations instance ListAcceptor (Data''1 a) a where { toListView (C''cons''1 x xs) = Left (x, xs); toListView (C''nil''1) = Right (); toListView (C''append''1 xs ys) = toListView (if isNull xs then ys else cons (hd xs) (append (tl xs) ys)); toListView (C''cons2''1 x1 x2 xs) = toListView (cons x1 (cons x2 xs)); }; instance List (Data''1 a) a where { cons = C''cons''1; nil = C''nil''1; }; instance AppendList (Data''1 a) a where { append = C''append''1; }; instance List2 (Data''1 a) a where { cons2 = C''cons2''1; }; instance ListAcceptor (Data''0 a) a where { toListView (C''cons''0 x xs) = Left (x, xs); toListView (C''nil''0) = Right (); toListView (C''append''0 xs ys) = toListView (if isNull xs then ys else cons (hd xs) (append (tl xs) ys)); toListView (C''cons2''0 x1 x2 xs) = toListView (cons x1 (cons x2 xs)); }; instance List (Data''0 a) a where { cons = C''cons''0; nil = C''nil''0; }; instance AppendList (Data''0 a) a where { append = C''append''0; }; instance List2 (Data''0 a) a where { cons2 = C''cons2''0; }; -- Cast(?) Declarations id''1 :: Data''1 a -> Data''1 a; id''1 x = x; id''0 :: Data''0 a -> Data''0 a; id''0 x = x; -- BindGroups isNull = (.) isNullView toListView; isNullView (Left (x, xs)) = False; isNullView (Right ()) = True; hd = (.) hdView toListView; hdView (Left (x, xs)) = x; tl = (.) tlView toListView; tlView (Left (x, xs)) = xs; baz = myLength (id''1 ys); ys = append xs xs; xs = cons2 ((*) 2 1) ((+) x 1) nil; x = 1; qux a = myLength (id''0 (append (cons2 a a nil) nil)); myLength = (.) myLengthView toListView; myLengthView (Left (x, xs)) = (+) 1 (myLength xs); myLengthView (Right ()) = 0;