packages feed

NonEmpty (empty) → 0.1

raw patch · 4 files changed

+77/−0 lines, 4 filesdep +basesetup-changed

Dependencies added: base

Files

+ Data/List/NonEmpty.hs view
@@ -0,0 +1,19 @@+module Data.List.NonEmpty where++-- | Tries to convert a list to a NonEmpty. Returns the NonEmpty if it can, or fails in the monad otherwise.+listToNonEmpty :: Monad m => [a] -> m (NonEmpty a)+listToNonEmpty s = do { (h:t) <- return s; return $ NonEmpty { neHead = h, neTail = t } }++-- | A non-empty list+data NonEmpty a+    = NonEmpty { neHead :: a+               , neTail :: [a]+               }++-- | Semantic function for NonEmpty+nonEmptyToList :: NonEmpty a -> [a]+nonEmptyToList ne = neHead ne : neTail ne++-- | Length of a given NonEmpty+length' :: NonEmpty a -> Int+length' = length . nonEmptyToList
+ LICENSE view
@@ -0,0 +1,30 @@++Copyright (c) 2009 Robin Green++Redistribution and use in source and binary forms, with or without+modification, are permitted provided that the following conditions are+met:++    * Redistributions of source code must retain the above copyright+      notice, this list of conditions and the following disclaimer.++    * Redistributions in binary form must reproduce the above+      copyright notice, this list of conditions and the following+      disclaimer in the documentation and/or other materials provided+      with the distribution.++    * Neither the name of Robin Green nor the names of other+      contributors may be used to endorse or promote products derived+      from this software without specific prior written permission.++THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS+"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT+LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR+A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT+OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,+SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT+LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,+DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY+THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT+(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE+OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ NonEmpty.cabal view
@@ -0,0 +1,25 @@+name:                NonEmpty+version:             0.1+Cabal-Version:	     >= 1.6+synopsis:            Library providing a non-empty list datatype, and total functions operating on it+description:         When you want to state that a list should always be non-empty, you can use this type.+		     This enables you to avoid the error of taking the head or tail of an empty list.+category:            Data+license:             BSD3+license-file:        LICENSE+copyright:	     Copyright (C) Robin Green 2009+author:              Robin Green+maintainer:          Robin Green <greenrd@greenrd.org>+build-type:	     Simple+stability:	     experimental+bug-reports:	     mailto:greenrd@greenrd.org+tested-with:	     GHC == 6.10.1++source-repository head+  type:     darcs+  location: http://patch-tag.com/publicrepos/NonEmpty++Library+  build-Depends:	base+  exposed-modules:      Data.List.NonEmpty+  ghc-options:          -Wall
+ Setup.lhs view
@@ -0,0 +1,3 @@+#!/usr/bin/env runhaskell+> import Distribution.Simple+> main = defaultMain