packages feed

constrained-some (empty) → 0.1.0.0

raw patch · 6 files changed

+163/−0 lines, 6 filesdep +basedep +constrained-some

Dependencies added: base, constrained-some

Files

+ CHANGELOG.md view
@@ -0,0 +1,12 @@+# Changelog++All notable changes to the constrained-some library will be documented in this+file.++The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),+and this project adheres to [PVP versioning](https://pvp.haskell.org/).++## Initial release: v0.0.1 _(2024-11-27)_++### Added+- Existentials `Somes` and `Somes1`
+ LICENSE view
@@ -0,0 +1,20 @@+Copyright (c) 2024 Julian Bruder++Permission is hereby granted, free of charge, to any person obtaining+a copy of this software and associated documentation files (the+"Software"), to deal in the Software without restriction, including+without limitation the rights to use, copy, modify, merge, publish,+distribute, sublicense, and/or sell copies of the Software, and to+permit persons to whom the Software is furnished to do so, subject to+the following conditions:++The above copyright notice and this permission notice shall be included+in all copies or substantial portions of the Software.++THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.+IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY+CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,+TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE+SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ README.md view
@@ -0,0 +1,28 @@+[![Hackage](https://img.shields.io/hackage/v/constrained-some.svg)](https://hackage.haskell.org/package/constrained-some) ![Static Badge](https://img.shields.io/badge/Lang-Haskell2010-blue) [![Haskell-CI](https://github.com/bruderj15/constrained-some/actions/workflows/haskell-ci.yml/badge.svg)](https://github.com/bruderj15/constrained-some/actions/workflows/haskell-ci.yml) [![License: GPL v3](https://img.shields.io/badge/License-MIT-blue.svg)](https://mit-license.org/)++# constrained-some++This library provides utilities for working with existential types and type-level constraints.+It allows you to enforce multiple constraints on polymorphic types and containers complementing `some`.++## Core++- **Existential Types**: `Somes` and `Somes1` provide existential wrappers for types with multiple constraints.+- **Convenient Aliases**: Simplified types `Some` and `Some1` for scenarios where just one constraint is needed.++## Usage++```haskell+import Data.Some.Constraint++someShowableOrd :: Somes '[Show, Ord]+someShowableOrd = Some (mempty :: [Double])++someNumFunctor :: Some1 Functor Num+someNumFunctor = Some1 $ [1, 2, 3 :: Int]+```++## Contact information+Contributions, critics and bug reports are welcome!++Please feel free to contact me through GitHub.
+ constrained-some.cabal view
@@ -0,0 +1,45 @@+cabal-version:      3.0+name:               constrained-some+version:            0.1.0.0+synopsis:           Existential type that can be constrained+description:        This library provides utilities for working with existential types and type-level constraints.+  It allows you to enforce multiple constraints on polymorphic types and containers complementing the package some.+homepage:           https://github.com/bruderj15/constrained-some+bug-reports:        https://github.com/bruderj15/constrained-some/issues+license:            MIT+license-file:       LICENSE+author:             Julian Bruder+maintainer:         julian.bruder@outlook.com+copyright:          © 2024 Julian Bruder+category:           Data, Dependent Types+build-type:         Simple+extra-source-files: README.md+extra-doc-files:    CHANGELOG.md+tested-with:+  GHC ==8.10.4+   || ==9.0.2+   || ==9.2.8+   || ==9.4.8+   || ==9.6.5+   || ==9.8.2+   || ==9.10.1++common warnings+    ghc-options: -Wall++library+    import:           warnings+    exposed-modules:  Data.Some.Constraint+    build-depends:    base >=4.12 && <4.21+    hs-source-dirs:   src+    default-language: Haskell2010++test-suite constrained-some-test+    import:           warnings+    default-language: Haskell2010+    type:             exitcode-stdio-1.0+    hs-source-dirs:   test+    main-is:          Main.hs+    build-depends:+        base >=4.12 && <4.21,+        constrained-some
+ src/Data/Some/Constraint.hs view
@@ -0,0 +1,54 @@+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE QuantifiedConstraints #-}+{-# LANGUAGE StandaloneKindSignatures #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE GADTs #-}++module Data.Some.Constraint where++import Data.Kind++-- | AllC ensures that a list of 'Constraint's is applied to a poly-kinded 'Type' @k@.+type AllC :: forall k. [k -> Constraint] -> k -> Constraint+type family AllC cs k :: Constraint where+  AllC '[]       k = ()+  AllC (c ': cs) k = (c k, AllC cs k)++-- | Existential with 'Constraint's.+--+-- ==== __Example__+--+-- @+-- someShowableOrd :: 'Somes' '['Show', 'Ord']+-- someShowableOrd = 'Some' ('mempty' :: ['Double'])+-- @+data Somes cs where+  Some :: forall+    (cs :: [Type -> Constraint])+    (a :: Type).+    AllC cs a => a -> Somes cs++-- | Alias for 'Somes' with just one 'Constraint'.+type Some c = Somes '[c]++-- | Existential for containers with 'Constraint's.+--+-- ==== __Example__+--+-- @+-- someNumFunctor :: 'Somes1' '['Functor'] '['Num']+-- someNumFunctor = 'Some1' $ [1, 2, 3 :: 'Int']+-- @+data Somes1 csf csa where+  Some1 :: forall+    k+    (csf :: [(k -> Type) -> Constraint])+    (csa :: [k -> Constraint])+    (f :: k -> Type)+    (a :: k).+    (AllC csf f, AllC csa a) => f a -> Somes1 csf csa++-- | Alias for 'Somes1' with just one 'Constraint'.+type Some1 ca cf = Somes1 '[ca] '[cf]
+ test/Main.hs view
@@ -0,0 +1,4 @@+module Main (main) where++main :: IO ()+main = putStrLn "Test suite not yet implemented."