Code Monkey home page Code Monkey logo

basic-prelude's People

Contributors

bergmark avatar danburton avatar debug-ito avatar gregwebs avatar instinctive avatar jml avatar nikita-volkov avatar pierrer avatar snoyberg avatar zoerb avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

basic-prelude's Issues

`asum` missing

I am debating on using basic-prelude or base-prelude.

The fact that basic-prelude doesn't expose asum from Data.Foldable is currently preventing me to consider basic-prelude.

Is there any reason why it is not included ? Would you consider including it ?

Export IOError in CorePrelude

I believe the module is quite essential, since many libraries throw exceptions of that type (this one, for instance).

I suggest to export all members of the module except the already exported functions for handling errors, of course.

Solidify and release version 0.3

We've made some api removals, so we need to bump the major version before the next release. Are there any other changes you'd like to make before we release v0.3? I'd like to do the changes proposed in #19 before release, and maybe improve the haddocks a little more.

empty = mempty

I like the concat = mconcat why not put in a similar empty = mempty ? It has a nice symmetry with Map.empty et al

Maybe these should not be in BasicPrelude?

, catch -- deprecated
, putChar
, getChar
, readLn
, interact

catch because it's deprecated (just make people import Prelude (catch) or import Control.Exception if they want a catch, I personally believe we should not be encouraging use of exceptions in general)

The others seem inconsistent with replacing default IO functions with Text equivalents

Word32

Why not export Word32 when exporting the other words?

Move list-specific functions out of CorePrelude

Now that I've created a full first-class module for Data.List, I've run into a few list-specific CorePrelude exports that don't really belong: or, elem, zip, zipWith, and unzip. BasicPrelude can still export these, but they don't belong in CorePrelude.

Add `getArgs` to CorePrelude

When writing Haskell programs, something I often reach for and have to end up importing is getArgs. I propose we add something like this to CorePrelude:

getArgs :: IO [Text]
getArgs = Data.List.map Data.Text.pack <$> System.Environment.getArgs

CorePrelude doesn't export any instances for LText and LByteString

A quite surprising fact. Here's a proof:

Prelude CorePrelude> :info LByteString 
type LByteString = Data.ByteString.Lazy.Internal.ByteString
    -- Defined in `CorePrelude'
Prelude CorePrelude> :info LText
type LText = Data.Text.Lazy.Internal.Text
    -- Defined in `CorePrelude'
Prelude CorePrelude> :info Text
data Text
  = Data.Text.Internal.Text {-# UNPACK #-} !Data.Text.Array.Array
                            {-# UNPACK #-} !Int
                            {-# UNPACK #-} !Int
    -- Defined in `Data.Text.Internal'
instance Eq Text -- Defined in `Data.Text'
instance Ord Text -- Defined in `Data.Text'
instance Read Text -- Defined in `Data.Text'
instance Show Text -- Defined in `Data.Text'
instance Typeable Text -- Defined in `Data.Text.Internal'
instance IsString Text -- Defined in `Data.Text'
instance Hashable Text -- Defined in `Data.Hashable'
instance Monoid Text -- Defined in `Data.Text'
Prelude CorePrelude> 

Text version of error?

Since using basic-prelude, I find myself writing this a lot:

   Left e -> error $ Text.unpack $ "Reason this couldn't ever happen: " ++ show e

Before using basic-prelude, I didn't need Text.unpack. It would be nice if basic-prelude exported an error that expected Text rather than String.

Export IsList

IsList (from GHC.Exts) is a useful typeclass that defines fromList and toList, and works with OverloadedLists. Note that toList should be hidden because it overlaps with Foldable.

Migrate core exports from BasicPrelude to CorePrelude

I believe the following should almost certainly be included in CorePrelude:

seq
($!)
curry
until
asTypeOf
undefined

Additionally, I think we should consider adding functions that deal with Read and Show, particularly showsPrec, readsPrec, and friends, though I consider these much lower priority than the above listed general purpose functions.

Is there anything else you think should be moved over to CorePrelude? Once we get this settled, then I think we should release version 0.2.

Suggested additions

almafa suggested a few additions on reddit:

Where are the list functions?!?

Also, if I understand correctly that this should be some enhanced Prelude, I have some feature requests (function names are negotiable):

  • when you add the list functions, also add (the new function) mapAccumL_ :)
  • add fst3, snd3, thd3 (possibly also the quadruple versions)
  • swap :: (a,b) -> (b,a)
  • add some Ord-based nub (for example the one which builds a set)
  • equating :: Eq a => (b -> a) -> b -> b -> Bool (so that you can say groupBy (equating f) . sortBy (comparing f)
  • sortOn, groupOn, groupSortOn, mapGroupSortOn (something like, mapGroupSortOn :: Ord b => (a -> b) -> (a -> c) -> [a] -> [(b,[c])])
  • strict sum/product
  • semantic editor combinators a la Conal
  • optionally re-export MVar, and add something like adjustMVar :: MVar a -> (a -> a) -> IO a and also adjustMVar_.

http://www.reddit.com/r/haskell/comments/y0kld/announce_basicprelude/c5shhtx

Better exception handling

I recently discovered and wrote about a proper way to catch all exceptions from some function, without messing up async exceptions. My question is: how, if at all, should this code be incorporated into basic-prelude? So far, my only change is to replace the async-unsafe catchAny family of functions in classy-prelude with this async-safe version described in that post. However, there are a number of other options:

  • Include catchAny in CorePrelude as well, exactly as implemented in classy-prelude.
  • As mentioned by @kudah (snoyberg/classy-prelude@2bbe34c#commitcomment-3628439) Include a more general version (catchSync) which could work for arbitrary exception types.
  • Maybe go even farther: replace the catch we currently export with a async-safe version. (@kudah called this "standard functions now turn 180° in meaning", but I don't really understand why that would be the case.)
  • We could also consider including the deepseq-enabled variants which fully evaluate return values.

I'm slightly tempted to export catch/try/handle as functions which use the async-safe trick and deepseq their return values, as I'm beginning to think this is the right way to handle exceptions for virtually all user code. However, I'm thinking that's too extreme a position. Any thoughts people have on this are welcome.

Export `Exception`-related stuff

I know that standard Prelude exports catch and probably some other functions. BasicPrelude exports none of such functions.

I suggest to export their "lifted" versions. At least the most important ones: throw, catch, handle.

Export `String` in CorePrelude instead of BasicPrelude

I'm not sure what the reasoning was behind the choice to export it in BasicPrelude, but because of this the ClassyPrelude lacks this essential type. Alternatively consider this a request to export String in ClassyPrelude.

Export a function to convert from `String` to `Text`

First of all I'd like to thank you so much for this package. It's amazing how much pain it's taken away from me! IMO it must be promoted in the community to become the next standard Prelude, because it fixes sooo many questionable decisions made in the current Prelude and does it quite elegantly.

I see that you generally replace String with Text, which I just love, but you can't replace it everywhere, and so in many sitiuations a requirement to convert from String to Text arises (for example, when a function from some library returns a String), but your Prelude doesn't export any function for that purpose.

I suggest you include the fromString function of the IsString typeclass, an instance of which exists for the Text type.

Release version 0.1 to hackage!

I don't have anything in particular that I would like to change right now, so let's go ahead and release this to hackage. I'll upload and announce it tomorrow, unless there are any objections, or unless you'd like to do it, Michael.

Export the `Data.Either` and `Data.Maybe` in whole

All the functions in those modules (Either, Maybe) export no conflicting symbols and their names make possibility of name-collisions highly unlikely. Yet those modules contain functions that are used quite often, and most of them are already exported in BasicPrelude anyway.

I personally miss the Either's lefts, rights and partitionEithers.

Provide a complete prelude, rename BasicPrelude?

First of all, it seems that both Michael and I have been thinking about extending this module with a very simple, complete Prelude replacement. So let's do that within this module.

Secondly, the name "BasicPrelude" seems to imply a complete Prelude. So I propose that this new complete Prelude receive the name BasicPrelude, and we move our current BasicPrelude.hs to a different name, for example, CorePrelude.hs or PartialPrelude.hs.

NoImplicitPrelude?

Instead of using the NoImplicitPrelude pseudo-extension, why not import Prelude hiding (things that need hiding) ?

Motivation: expressing intentions in standard Haskell code wherever possible :)

Lazy versions don’t export instances

Since CorePrelude only exports lazy versions like

type LByteString = Data.ByteString.Lazy.ByteString

instances like e.g. toString are not re-exported.

Is there any way around that?

Improve haddocks for BasicPrelude

The way I wrote BasicPrelude isn't very good for documentation. It should be rewritten to match CorePrelude style so that the docs for each method it exports will be available. The exception is CorePrelude: we should simply re-export that module in its entirety; no need for its docs to be repeated if it is fully re-exported.

empty clashes with Control.Applicative

Control.Applicative exports the Alternative typeclass, which includes empty. While the empty name very much deserves to go to Monoid, as basic-prelude currently does, this may make it a pain to work with Alternative code.

Thoughts?

‘show’ is not a (visible) method of class ‘Show’

When declaring a new instance of the typeclass Show:

{-# LANGUAGE NoImplicitPrelude, OverloadedStrings #-}
module PreludeTest where

import BasicPrelude

data Foo = Foo { bar :: Int, baz :: Bool }

instance Show Foo where
    show foo = "Foo { bar = " ++ show (bar foo) ++
                   ", baz = " ++ show (baz foo) ++ " }"

Trying to compile this code gives the error ‘show’ is not a (visible) method of class ‘Show’. I can't seem to find any workarounds that don't involve simply hiding the relevant imports from BasicPrelude, and importing them directly from GHC.Show.

This may be a simple case of PEBKAC, and I'm just missing something obvious, but I can't think what it could possibly be. Is this the intended behaviour?

Generalize `concat`, `concatMap` and `intercalate`?

Currently they have the following types:

concat :: Monoid w => [w] -> w
concatMap :: Foldable t => (a -> [b]) -> t a -> [b]
intercalate :: Monoid w => w -> [w] -> w

which can be potentially generalized to

concat :: (Foldable t, Monoid w) => t w -> w
concatMap :: (Foldable t, Monoid w) => (a -> w) -> t a -> w
intercalate :: (Foldable t, Monoid w) => w -> t w -> w

in particular concatMap is just foldMap. The only reason I see why not to do this is that a generic implementation may be inefficient for some (Foldable t, Monoid w) instances.

Provide basic list splitting functions in basic prelude

For when we would like to avoid a dependency on the complete split package. I personally use these two most often in my code -

splitWhen :: (a -> Bool) -> [a] -> [[a]]
splitWhen p s = case dropWhile p s of
  [] -> []
  s' -> w : splitWhen p s''
    where (w, s'') = break p s'

splitOn :: Eq a => a -> [a] -> [[a]]
splitOn c = splitWhen (==c)

Restrict to packages portable across GHCs?

Until http://trac.haskell.org/vector/ticket/89 is resolved, installing basic-prelude for my cross-compiler is annoying. This is not a big deal, but it put me in mind that there might come a time where someone wants something that depends on TemplateHaskell included as a dependency, which does not work when cross-compiling or compiling for ARM or MIPS. How do others feel about having a policy of avoiding such dependencies in general?

CorePrelude should export Read

It doesn't have to export the innards of the typeclass, but similar to how it exports Show, it should also export Read.

Add Lazy HashMap and Unboxed Vector

We already provide Lazy variants for Text and ByteString, what do you think about including LHashMap as well? Also, unboxed vectors are typically a Good Thing, can we throw UVector into the mix too? Mainly I ask because these are two modules that I already included in Modular Prelude, due to their similarity to the comparable modules. Writing Classy Prelude instances for them should be trivial, although UVector requires additional Unbox constraints.

Export `Data.Text.Encoding`

This module is very useful for working with Text and ByteString. But I suspect the idea of exporting it may raise a debate because there exists a conflicting version of this module for Lazy Text. But, since the strict version of Text is the default type used for strings in BasicPrelude, I believe exporting this module as a default one looks consistent enough. Those who need a lazy version will need to work with qualified imports anyway.

BSD3 license?

If I'm not mistaken, BSD3 is the popular licence within the Haskell community. Is there any particular reason you started this project (and ClassyPrelude) with the MIT license? Should we switch over to BSD3? I'm OK with either one.

Move `empty` and `concat` out of CorePrelude

I've been working on upgrading modular-prelude to use the new basic- and classy- preludes, and I realized that overloading emptyand concat is in conflict with the principle of Modular Prelude, which is that a "module" should always bring the most specific version of a function into scope.

I propose that we remove empty and concat from CorePrelude, and add them to BasicPrelude. (ClassyPrelude will likely want to add these definitions to ClassyPrelude.hs).

Provided ``sum`` is not general enough

From what I can tell, the sum function provided by BasicPrelude has type (Num a) => [a] -> a, while the one in Data.List (at least, most recently) has the type (Foldable t, Num a) => t a -> a, which is more general and useful. Is there a reason for this choice?

mintercalate

Instead of Data.Text.intercalate for BasicPrelude, why not:

intercalate xs xss = mconcat $ intersperse xs xss

This is useful, for exampl, with Builders as well.

Extended Kleisli combinators

What do you guys think about reexporting the Kleislify library? From a standpoint that CorePrelude is a basis for preludes targeted at advanced users, this makes a whole lot of sense.

It's quite useful for situations when you have to utilize return to compose things. E.g. it allows you to reduce this:

stripPrefix' prefix = stripPrefix prefix >=> return . toLower

into this:

stripPrefix' prefix = stripPrefix prefix =>^ toLower

`oo`

This is a bit more of a departure from basic stuff, similar to the Foldable discussion, but I've been thinking it might be useful to include:

o = (.)
oo = o . o
ooo = oo . o

Up to some reasonable number (which might even just be 3).

Thoughts?

map = fmap

Similar to the issue for empty = mempty, and the already implemented concat, I think you should consider exporting a function named map which equals Prelude.fmap.

Filesystem.Path.CurrentOS?

All of the imports/re-exports here make sense as very common things a very large number of programs want to import at some point. Filesystem.Path.CurrentOS seems the odd one out. I've never even used that (I use http://hackage.haskell.org/package/filepath) and either way, it only really makes sense in applications that are dealing with the filesystem.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.