GithubHelp home page GithubHelp logo

athanclark / pred-trie Goto Github PK

View Code? Open in Web Editor NEW
5.0 3.0 0.0 1.63 MB

predicative lookup container

License: BSD 3-Clause "New" or "Revised" License

Haskell 100.00%
haskell predicates lookup trie parametric-polymorphism

pred-trie's Introduction

pred-trie

A predicative trie library - use predicates instead of literal match to capture classes of results, instead of enumerating distinguished ones.

Usage

The predicates are existentially quantified such that a predicate creates an unknown type, while it's result must have the necessary arity, matching the quantified type, to fulfill the lookup:

PredTrie s a
  = PNil
  | forall t. PCons
      { predicate :: s -> Maybe t
      , result    :: t -> a
      }

...basically.

I broke the lookup phases into "steps", like the tries package, and used the fastest-lookup HashMapStep trie implementation for the literal lookups. For more info, read the code :D

How to run tests

stack test

Benchmarking

stack bench --benchmark-arguments="--output profile.html"

pred-trie's People

Contributors

athanclark avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

pred-trie's Issues

test/Spec.hs:3:8: Could not find module ‘Data.Trie.Pred.UnifiedSpec’

from the stackage nightly build:

Preprocessing test suite 'spec' for pred-trie-0.2.3...

test/Spec.hs:3:8:
    Could not find module ‘Data.Trie.Pred.UnifiedSpec’
    Perhaps you meant
      Data.Trie.Pred.Unified (needs flag -package-key pred-trie-0.2.3@predt_5RCO4h5Qjqg09vtX6PrPeU)
      Data.Trie.Pred.Unified (needs flag -package-key pred-trie-0.2.3@predt_23KeJIiByNa19Z2Yd27xr9)
      Data.Trie.Pred.Unified.Tail (needs flag -package-key pred-trie-0.2.3@predt_5RCO4h5Qjqg09vtX6PrPeU)
    Use -v to see a list of the files searched for.

The package itself seemed to build okay.

Compilation failure with newest dependencies

[3 of 4] Compiling Data.Trie.Pred.Unified.Tail ( src/Data/Trie/Pred/Unified/Tail.hs, dist/build/Data/Trie/Pred/Unified/Tail.o )

src/Data/Trie/Pred/Unified/Tail.hs:55:23:
    Couldn't match expected type ‘a7 -> b8 -> c7’
                with actual type ‘UPTrie t (r -> x)’
    Relevant bindings include
      xrs :: UPTrie t (r -> x)
        (bound at src/Data/Trie/Pred/Unified/Tail.hs:55:16)
      t :: t (bound at src/Data/Trie/Pred/Unified/Tail.hs:55:14)
      p :: t -> Maybe r
        (bound at src/Data/Trie/Pred/Unified/Tail.hs:55:12)
      suppliment :: (t -> Maybe r)
                    -> t -> UPTrie t (r -> x) -> Maybe (UPTrie t x)
        (bound at src/Data/Trie/Pred/Unified/Tail.hs:55:1)
    In the first argument of ‘(<~$>)’, namely ‘xrs’
    In the first argument of ‘(<$>)’, namely ‘(xrs <~$>)’

src/Data/Trie/Pred/Unified/Tail.hs:96:72:
    Couldn't match type ‘UPTrie t1 (r -> a9 -> c)’ with ‘a9 -> b9 -> c’
    Expected type: [a9 -> b9 -> c]
      Actual type: [UPTrie t1 (r -> a9 -> c)]
    Relevant bindings include
      xrs :: [UPTrie t1 (r -> a9 -> c)]
        (bound at src/Data/Trie/Pred/Unified/Tail.hs:95:25)
      mrx :: Maybe (r -> a9 -> c)
        (bound at src/Data/Trie/Pred/Unified/Tail.hs:95:21)
      p :: t1 -> Maybe r
        (bound at src/Data/Trie/Pred/Unified/Tail.hs:95:19)
      t :: t1 (bound at src/Data/Trie/Pred/Unified/Tail.hs:95:17)
      go :: UPTrie t1 (a9 -> c) -> WrappedMonoid (Maybe (a9 -> c))
        (bound at src/Data/Trie/Pred/Unified/Tail.hs:94:7)
    In the second argument of ‘mapMaybe’, namely ‘xrs’
    In the first argument of ‘mconcat’, namely
      ‘(mapMaybe
          (\ z -> (\ r -> unwrapMonoid $ go $ z <~$> r) <$> p t) xrs)’

pred-trie 0.4.0 build failure

Reproduce this like so:

  • stack unpack pred-trie-0.4.0 && cd pred-trie-0.4.0
  • stack init --resolver 2015-12-30
  • Add the following extra-deps to the generated stack.yaml
    • composition-extra-2.0.0
    • tries-0.0.4
    • rose-trees-0.0.3
    • sets-0.0.5
  • stack build
Preprocessing library pred-trie-0.4.0...
[1 of 2] Compiling Data.Trie.Pred.Step ( src/Data/Trie/Pred/Step.hs, dist/build/
Data/Trie/Pred/Step.o )

src/Data/Trie/Pred/Step.hs:49:10: Warning:
    No explicit implementation for
      ‘insert’
    In the instance declaration for ‘Trie NonEmpty s (PredStep c)’

src/Data/Trie/Pred/Step.hs:73:10: Warning:
    No explicit implementation for
      ‘insert’
    In the instance declaration for ‘Trie NonEmpty s (PredSteps c)’

[2 of 2] Compiling Data.Trie.Pred   ( src/Data/Trie/Pred.hs, dist/build/Data/Tri
e/Pred.o )

src/Data/Trie/Pred.hs:110:7:
    Couldn't match expected type ‘HT.HashMapChildren t s t1’
                with actual type ‘(Maybe t2, Maybe (PredTrie s t2))’
    Relevant bindings include
      xs :: HM.HashMap s (HT.HashMapChildren t s t1)
        (bound at src/Data/Trie/Pred.hs:109:27)
      goLit :: HT.HashMapStep t s t1 -> Maybe (NonEmpty s, t2, [s])
        (bound at src/Data/Trie/Pred.hs:109:5)
      goPred :: forall t.
                PredStep PredTrie s t -> Maybe (NonEmpty s, t, [s])
        (bound at src/Data/Trie/Pred.hs:118:5)
      ps :: [PredStep PredTrie s a]
        (bound at src/Data/Trie/Pred.hs:106:41)
      ls :: HT.HashMapStep PredTrie s a
        (bound at src/Data/Trie/Pred.hs:106:27)
      ts :: [s] (bound at src/Data/Trie/Pred.hs:106:13)
      (Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant
-binds)
    In the pattern: (mx, mxs)
    In a stmt of a 'do' block: (mx, mxs) <- HM.lookup t xs
    In the expression:
      do { (mx, mxs) <- HM.lookup t xs;
           let mFoundHere = ...;
           if null ts then
               mFoundHere
           else
               getFirst
               $ First
                   (do { (pre, y, suff) <- matchPT (NE.fromList ts) =<< mxs;
                         return (t :| NE.toList pre, y, suff) })
                 <> First mFoundHere }

src/Data/Trie/Pred.hs:135:7:
    Couldn't match expected type ‘HT.HashMapChildren t s t1’
                with actual type ‘(Maybe t2, Maybe (PredTrie s t2))’
    Relevant bindings include
      xs :: HM.HashMap s (HT.HashMapChildren t s t1)
        (bound at src/Data/Trie/Pred.hs:134:27)
      goLit :: HT.HashMapStep t s t1 -> Maybe [(NonEmpty s, t2, [s])]
        (bound at src/Data/Trie/Pred.hs:134:5)
      goPred :: forall t.
                PredStep PredTrie s t -> Maybe [(NonEmpty s, t, [s])]
        (bound at src/Data/Trie/Pred.hs:144:5)
      ps :: [PredStep PredTrie s a]
        (bound at src/Data/Trie/Pred.hs:131:43)
      ls :: HT.HashMapStep PredTrie s a
        (bound at src/Data/Trie/Pred.hs:131:29)
      ts :: [s] (bound at src/Data/Trie/Pred.hs:131:15)
      (Some bindings suppressed; use -fmax-relevant-binds=N or -fno-max-relevant-binds)
    In the pattern: (mx, mxs)
    In a stmt of a 'do' block: (mx, mxs) <- HM.lookup t xs
    In the expression:
      do { (mx, mxs) <- HM.lookup t xs;
           let mFoundHere = ...
               prependAncestry (pre, x, suff) = ...;
           if null ts then
               mFoundHere
           else
               do { foundHere <- mFoundHere;
                    .... } }

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.