Skip to content

Commit

Permalink
update code to work with oeis2
Browse files Browse the repository at this point in the history
  • Loading branch information
byorgey committed Oct 11, 2024
1 parent 2974023 commit 860be23
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 29 deletions.
2 changes: 1 addition & 1 deletion disco.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
File renamed without changes.
File renamed without changes.
52 changes: 24 additions & 28 deletions src/Disco/Interpret/CESK.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 (..),
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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/<oeis_sequence_id>"'
-- 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/<oeis_sequence_id>"'
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
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 comments on commit 860be23

Please sign in to comment.