mauke / data-default Goto Github PK
View Code? Open in Web Editor NEWA class for types with a default value
A class for types with a default value
My opinion: def
is a useful concept for blobs of optional parameters, configs, and perhaps other domain-specific things, but not for numeric types, lists, Maybe, etc.
The situation today is, from my vantage point: either people avoid this type class entirely (e.g. google/proto-lens#194), or they use it with some caveats like, try not to abuse it.
I propose we try to correct this by making a major version bump to 2.0 and removing most instances. The only ones I believe belong are the derived tuple instances like
instance (Default a, Default b) => Default (a, b)
What do you think? Is this a feasible or wanted change? Thanks :)
{-# LANGUAGE DefaultSignatures #-}
import Data.Monoid
class Default a where
def :: a
default def :: Monoid a => a
def = mempty
Please refresh your library dependencies to become compatible with stack tools. It guess it should compiles with latest versions of cabal packages
The usefulness of the Default class came from its ability to generically derive Default
instances. I would argue that adding a GDefault
instance for sum types (which selects the first constructor) would further boost its usefulness. Plus we lose nothing from adding this since right now we need to manually write Default instances for sum types anyways.
Do you personally use the (e -> r) instance? Do you know if anybody else does? I'm trying to define:
data Preference = Preference
{ userId :: UserId
, max :: Int
}
Obviously, the UserId can't be defaulted (sensibly -- i.e., while respecting the app's semantics for a UserId), but it would be pretty nice to be able to define:
instance Default (UserId -> Preference) where
def = \uid -> (Preference uid 1000)
It would be useful to have a default for Proxy
instance Default (Proxy a) where def = Proxy
Hello, this library looks really good to me and i would like to use it in my haskell stack project. Could it be added to stackage ?
I may be missing something, but as I see it the reason to split the original data-default
into separate packages is to minimize dependencies.
As both data-default-class
and data-default-instances-base
only introduce the base
dependency, we could merge the packages.
Keeping the separate packages has the downside that the instances in data-default-instances-base
are orphan (which I generally considered undesirable). Are there any upsides?
The current instance isn't very useful and it occupies the space for a whole universe of way more useful default morphism instances, e.g.:
instance Default (Int8 -> Int) where def = fromIntegral
instance Default (String -> Data.Text.Text) where def = Data.Text.pack
Basically, the whole "conversion" ecosystem could be encoded this way.
Currently it's missing. Should return False.
This has the unfortunate effect of violating the PVP contract, as data-default-class-0.1.0 lacks Generics support for GHC 7.4 even though GHC 7.4 does support Generics and will result in hard to fix install-plan issues on Hackage if left un-addressed.
My recommendation is to quickly release data-default-class-0.1.0.1 providing Generics support for GHC 7.4. I can provide a PR if needed.
It would be nice to have new version released with Generics support.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.