From 28e79a36d2760a15d59c4cc08af0b0700404ccb0 Mon Sep 17 00:00:00 2001 From: Willem Van Onsem Date: Fri, 30 Apr 2021 11:22:51 +0200 Subject: [PATCH] introduce Default1 in a similar way like Eq1, Ord1, etc. --- data-default-class/Data/Default/Class.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/data-default-class/Data/Default/Class.hs b/data-default-class/Data/Default/Class.hs index 8943fdb..5b24ec6 100644 --- a/data-default-class/Data/Default/Class.hs +++ b/data-default-class/Data/Default/Class.hs @@ -86,6 +86,17 @@ class Default a where def = to gdef #endif +-- | A class to specify that complex type with a default wrapped type, +class Default1 (f :: * -> *) where + liftDef :: a -> f a + +-- | Create a default value by making use of the 'Default1' instance +-- and the 'def' function as default for the item(s) wrapped in the object. +def1 :: (Default1 f, Default a) + => f a -- ^ The default object constructed with the 'Default1' and the 'def' + -- of the wrapped item. +def1 = liftDef def + instance Default Int where def = 0 instance Default Int8 where def = 0 instance Default Int16 where def = 0