summaryrefslogtreecommitdiff
path: root/testsuite/tests/safeHaskell/safeLanguage/SafeLang06_A.hs
diff options
context:
space:
mode:
Diffstat (limited to 'testsuite/tests/safeHaskell/safeLanguage/SafeLang06_A.hs')
-rw-r--r--testsuite/tests/safeHaskell/safeLanguage/SafeLang06_A.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/testsuite/tests/safeHaskell/safeLanguage/SafeLang06_A.hs b/testsuite/tests/safeHaskell/safeLanguage/SafeLang06_A.hs
new file mode 100644
index 0000000000..d092ae7a1a
--- /dev/null
+++ b/testsuite/tests/safeHaskell/safeLanguage/SafeLang06_A.hs
@@ -0,0 +1,24 @@
+{-# LANGUAGE Trustworthy #-}
+
+-- | Here we expose a MinList API that only allows elements
+-- to be inserted into a list if they are at least greater
+-- than an initial element the list is created with.
+module SafeLang06_A (
+ MinList,
+ newMinList,
+ insertMinList,
+ printIntMinList
+ ) where
+
+data MinList a = MinList a [a]
+
+newMinList :: Ord a => a -> MinList a
+newMinList n = MinList n []
+
+insertMinList :: Ord a => MinList a -> a -> MinList a
+insertMinList s@(MinList m xs) n | n > m = MinList m (n:xs)
+ | otherwise = s
+
+printIntMinList :: MinList Int -> IO ()
+printIntMinList (MinList min xs) = putStrLn $ "MinList Int :: MinList " ++ show min ++ " " ++ show xs
+