Skip to content

Commit

Permalink
Update on Hackage
Browse files Browse the repository at this point in the history
  • Loading branch information
OleksandrZhabenko committed Dec 28, 2020
0 parents commit 6926ae6
Show file tree
Hide file tree
Showing 5 changed files with 126 additions and 0 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Revision history for phonetic-languages-permutations

## 0.1.0.0 -- 2020-11-19

* First version. Released on an unsuspecting world.

## 0.1.1.0 -- 2020-11-19

* First version revised A. Some code improvements.

## 0.2.0.0 -- 2020-11-20

* Second version. Added three more functions for permutations.

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright (c) 2020 OleksandrZhabenko

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.
65 changes: 65 additions & 0 deletions Phonetic/Languages/Permutations.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
-- |
-- Module : Phonetic.Languages.Permutations
-- Copyright : (c) OleksandrZhabenko 2020
-- License : MIT
-- Stability : Experimental
-- Maintainer : [email protected]
--
-- Commonly used versions of the @phonetic-languages-common@ package functions.

module Phonetic.Languages.Permutations (
universalSetG
, universalSetGL
, genPermutations
, genPermutationsV
, genPermutationsL
, genPermutationsVL
) where

import qualified Data.Vector as VB
import qualified Data.List as L (permutations)
import Data.SubG
import Data.SubG.InstancesPlus ()
import qualified Data.Foldable as F (concat,foldr')
--import Data.List ()
import Data.Monoid

-- | A key point of the evaluation -- the universal set of the task represented as a 'VB.Vector' of 'VB.Vector' of @a@.
universalSetG ::
(Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a
-> t (t a)
-> (t a -> VB.Vector a) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of @a@ so that the function can process further the permutations
-> ((t (t a)) -> VB.Vector (VB.Vector a)) -- ^ The function that is used internally to convert to the boxed 'VB.Vector' of 'VB.Vector' of @a@ so that the function can process further
-> VB.Vector (VB.Vector Int) -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).
-> VB.Vector (VB.Vector a)
-> VB.Vector (VB.Vector a)
universalSetG ts uss f1 f2 perms baseV = VB.map (VB.foldr' mappend mempty . VB.cons (f1 ts) . (`mappend` (f2 uss)) . VB.unsafeBackpermute baseV) perms
{-# INLINE universalSetG #-}

-- | A key point of the evaluation -- the universal set of the task represented as a 'VB.Vector' of 'VB.Vector' of @a@. Because the order is not
universalSetGL ::
(Eq a, Foldable t, InsertLeft t a, Monoid (t a), Monoid (t (t a))) => t a
-> t (t a)
-> (t a -> [a]) -- ^ The function that is used internally to convert to the @[a]@ so that the function can process further the permutations
-> ((t (t a)) -> [[a]]) -- ^ The function that is used internally to convert to the needed representation so that the function can process further
-> [VB.Vector Int] -- ^ The list of permutations of 'Int' indices starting from 0 and up to n (n is probably less than 7).
-> VB.Vector [a]
-> [[a]]
universalSetGL ts uss f1 f2 permsL baseV = map (F.concat . F.foldr' (:) [] . (f1 ts:) . (`mappend` f2 uss) . VB.toList . VB.unsafeBackpermute baseV) permsL
{-# INLINE universalSetGL #-}

genPermutations :: Int -> VB.Vector (VB.Vector Int)
genPermutations n = VB.map VB.fromList . VB.fromList . L.permutations . take n $ [0..]
{-# INLINE genPermutations #-}

genPermutationsV :: VB.Vector (VB.Vector (VB.Vector Int))
genPermutationsV = VB.map (\n -> VB.map VB.fromList . VB.fromList . L.permutations . take n $ [0..]) . VB.enumFromTo 2 $ 7
{-# INLINE genPermutationsV #-}

genPermutationsL :: Int -> [VB.Vector Int]
genPermutationsL n = map VB.fromList . L.permutations . take n $ [0..]
{-# INLINE genPermutationsL #-}

genPermutationsVL :: VB.Vector [VB.Vector Int]
genPermutationsVL = VB.map (\n -> map VB.fromList . L.permutations . take n $ [0..]) . VB.enumFromTo 2 $ 7
{-# INLINE genPermutationsVL #-}
2 changes: 2 additions & 0 deletions Setup.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import Distribution.Simple
main = defaultMain
25 changes: 25 additions & 0 deletions phonetic-languages-permutations.cabal
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
-- Initial phonetic-languages-permutations.cabal generated by cabal init.
-- For further documentation, see http://haskell.org/cabal/users-guide/

name: phonetic-languages-permutations
version: 0.2.0.0
synopsis: Commonly used versions of the phonetic-languages-common package
description: Permutations-related to produce universal set of the task.
homepage: https://hackage.haskell.org/package/phonetic-languages-permutations
license: MIT
license-file: LICENSE
author: OleksandrZhabenko
maintainer: [email protected]
copyright: Oleksandr Zhabenko
category: Language,Math,Game
build-type: Simple
extra-source-files: CHANGELOG.md
cabal-version: >=1.10

library
exposed-modules: Phonetic.Languages.Permutations
-- other-modules:
-- other-extensions:
build-depends: base >=4.8 && <4.15, vector >=0.11 && <0.14, subG >=0.4.2 && <1, subG-instances >=0.1 && <1
-- hs-source-dirs:
default-language: Haskell2010

0 comments on commit 6926ae6

Please sign in to comment.