Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce Default1 in a similar way like Eq1, Ord1, etc. #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions data-default-class/Data/Default/Class.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down