From 860be2335766f6bddfed9cad14f89d0cc339f394 Mon Sep 17 00:00:00 2001 From: Brent Yorgey Date: Fri, 11 Oct 2024 14:30:14 -0500 Subject: [PATCH] update code to work with oeis2 --- disco.cabal | 2 +- {failing => example}/catalan.disco | 0 {failing => lib}/oeis.disco | 0 src/Disco/Interpret/CESK.hs | 52 ++++++++++------------ {failing => test}/lib-oeis/expected | 0 {failing => test}/lib-oeis/input | 0 {failing => test}/pretty-issue258/expected | 0 {failing => test}/pretty-issue258/input | 0 8 files changed, 25 insertions(+), 29 deletions(-) rename {failing => example}/catalan.disco (100%) rename {failing => lib}/oeis.disco (100%) rename {failing => test}/lib-oeis/expected (100%) rename {failing => test}/lib-oeis/input (100%) rename {failing => test}/pretty-issue258/expected (100%) rename {failing => test}/pretty-issue258/input (100%) diff --git a/disco.cabal b/disco.cabal index bcffc967..869afda9 100644 --- a/disco.cabal +++ b/disco.cabal @@ -525,7 +525,7 @@ executable disco containers >= 0.5 && < 0.8, unbound-generics >= 0.3 && < 0.5, lens >= 4.14 && < 5.4, - optparse-applicative >= 0.12 && < 0.19 + optparse-applicative >= 0.12 && < 0.19, oeis2 >= 1.0.0 && < 1.1 default-language: Haskell2010 diff --git a/failing/catalan.disco b/example/catalan.disco similarity index 100% rename from failing/catalan.disco rename to example/catalan.disco diff --git a/failing/oeis.disco b/lib/oeis.disco similarity index 100% rename from failing/oeis.disco rename to lib/oeis.disco diff --git a/src/Disco/Interpret/CESK.hs b/src/Disco/Interpret/CESK.hs index 63e2e011..56328e04 100644 --- a/src/Disco/Interpret/CESK.hs +++ b/src/Disco/Interpret/CESK.hs @@ -32,6 +32,7 @@ import qualified Data.List.Infinite as InfList import qualified Data.Map as M import Data.Maybe (isJust) import Data.Ratio +import qualified Data.Text as T import Disco.AST.Core import Disco.AST.Generic ( Ellipsis (..), @@ -41,6 +42,8 @@ import Disco.AST.Generic ( import Disco.AST.Typed (AProperty) import Disco.Compile import Disco.Context as Ctx +import Disco.Effects.Fresh +import Disco.Effects.Input import Disco.Enumerate import Disco.Error import Disco.Names @@ -51,15 +54,12 @@ import Math.Combinatorics.Exact.Binomial (choose) import Math.Combinatorics.Exact.Factorial (factorial) import Math.NumberTheory.Primes (factorise, unPrime) import Math.NumberTheory.Primes.Testing (isPrime) - --- import Math.OEIS ( --- catalogNums, --- extendSequence, --- lookupSequence, --- ) - -import Disco.Effects.Fresh -import Disco.Effects.Input +import Math.OEIS ( + SearchStatus (SubSeq), + extendSeq, + lookupSeq, + number, + ) import Polysemy import Polysemy.Error import Polysemy.Random @@ -356,8 +356,8 @@ appConst k = \case -- Sequences OUntil -> arity2 $ \v1 -> out . ellipsis (Until v1) - -- OLookupSeq -> out . oeisLookup - -- OExtendSeq -> out . oeisExtend + OLookupSeq -> out . oeisLookup + OExtendSeq -> out . oeisExtend -------------------------------------------------- -- Comparison @@ -643,23 +643,19 @@ constdiff (x : xs) -- OEIS ------------------------------------------------------------ --- -- | Looks up a sequence of integers in OEIS. --- -- Returns 'left()' if the sequence is unknown in OEIS, --- -- otherwise 'right "https://oeis.org/"' --- oeisLookup :: Value -> Value --- oeisLookup (vlist vint -> ns) = maybe VNil parseResult (lookupSequence ns) --- where --- parseResult r = VInj R (listv charv ("https://oeis.org/" ++ seqNum r)) --- seqNum = getCatalogNum . catalogNums - --- getCatalogNum [] = error "No catalog info" --- getCatalogNum (n : _) = n - --- -- | Extends a Disco integer list with data from a known OEIS --- -- sequence. Returns a list of integers upon success, otherwise the --- -- original list (unmodified). --- oeisExtend :: Value -> Value --- oeisExtend = listv intv . extendSequence . vlist vint +-- | Looks up a sequence of integers in OEIS. +-- Returns 'left()' if the sequence is unknown in OEIS, +-- otherwise 'right "https://oeis.org/"' +oeisLookup :: Value -> Value +oeisLookup (vlist vint -> ns) = maybe VNil parseResult (lookupSeq (SubSeq ns)) + where + parseResult r = VInj R (listv charv ("https://oeis.org/" ++ T.unpack (number r))) + +-- | Extends a Disco integer list with data from a known OEIS +-- sequence. Returns a list of integers upon success, otherwise the +-- original list (unmodified). +oeisExtend :: Value -> Value +oeisExtend = listv intv . extendSeq . vlist vint ------------------------------------------------------------ -- Normalizing bags/sets diff --git a/failing/lib-oeis/expected b/test/lib-oeis/expected similarity index 100% rename from failing/lib-oeis/expected rename to test/lib-oeis/expected diff --git a/failing/lib-oeis/input b/test/lib-oeis/input similarity index 100% rename from failing/lib-oeis/input rename to test/lib-oeis/input diff --git a/failing/pretty-issue258/expected b/test/pretty-issue258/expected similarity index 100% rename from failing/pretty-issue258/expected rename to test/pretty-issue258/expected diff --git a/failing/pretty-issue258/input b/test/pretty-issue258/input similarity index 100% rename from failing/pretty-issue258/input rename to test/pretty-issue258/input