From 5cd664fe805f5c026c908ac0202edc30f28106b7 Mon Sep 17 00:00:00 2001 From: Jan Sucan Date: Fri, 10 Mar 2023 16:12:15 +0100 Subject: 3_a_1: Add solution --- ch03/3_a_1.hs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 ch03/3_a_1.hs (limited to 'ch03') diff --git a/ch03/3_a_1.hs b/ch03/3_a_1.hs new file mode 100644 index 0000000..6e2b634 --- /dev/null +++ b/ch03/3_a_1.hs @@ -0,0 +1,14 @@ +-- Write the converse of fromList for the List type: a function that takes a +-- List a and generates a [a]. + +{-- From examples/examples/ch03/ListADT.hs --} +data List a = Cons a (List a) + | Nil + deriving (Show) +{-- End of code from examples --} + +toList (Cons x xs) = x:(toList xs) +toList Nil = [] + +-- ghci> toList (Cons 1 (Cons 2 (Cons 3 Nil))) +-- [1,2,3] -- cgit v1.2.3