-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add lookupSequence, extendSequence for OEIS access #202
Conversation
5b45db0
to
4c8b254
Compare
Thanks! Sorry it's taken me a while to look at it, I was away for a few days with my family. |
@@ -0,0 +1,7 @@ | |||
using Primitives | |||
|
|||
lookupSequence : List N -> Unit + List Char |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be good to include some documentation and examples attached to these functions here, using |||
(documentation) and !!!
(doctest/quickcheck) syntax.
@@ -905,6 +909,9 @@ whnfOp OUntil = arity2 "until" $ ellipsis . Until | |||
whnfOp OCrash = arity1 "crash" $ whnfV >=> primCrash | |||
whnfOp OId = arity1 "id" $ whnfV | |||
|
|||
whnfOp OExtendSeq = arity1 "extendSequence" $ whnfV >=> oeisExtend | |||
whnfOp OLookupSeq = arity1 "lookupSequence" $ whnfV >=> oeisLookup | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not really necessary to call whnfV
(which reduces a value to weak head normal form) before calling oeisExtend
or oeisLookup
here: weak head normal form on a list only tells you if it is empty or a cons, and they both call fromDiscoList
which evaluates the entire list anyway.
src/Disco/Interpret/Core.hs
Outdated
l <- toDiscoList $ toVal ("https://oeis.org/" ++ sequence) | ||
return $ VCons 1 [l] -- right "https://oeis.org/foo" | ||
fromVNum (VNum _ x) = fromIntegral $ numerator x | ||
fromVNum v = error $ "Impossible! fromVNum on " ++ show v |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since fromVNum
is duplicated in both oeisLookup
and oeisExtend
, why not pull it out into its own top-level definition? Yes, it's extremely partial, but it's OK as long as we document it.
src/Disco/Interpret/Core.hs
Outdated
vs <- fromDiscoList v | ||
let xs = map fromVNum vs | ||
let newseq = extendSequence xs | ||
toDiscoList $ map (\i -> vnum (i % 1)) newseq |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The lambda could also be written vnum . (%1)
. Personally I find that easier to read, though tastes differ.
test/lib-oeis/input
Outdated
@@ -0,0 +1,6 @@ | |||
:load lib/oeis.disco |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since it's in the stdlib, it should work to say import oeis
instead of :load lib/oeis.disco
.
lookupSequence [] | ||
|
||
extendSequence [1,3,5,7] | ||
extendSequence [] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe let's also add a test doing lookup and extend on a long and/or random sequence of numbers that isn't in the OEIS.
-- OEIS | ||
------------------------------------------------------------ | ||
|
||
oeisLookup :: Value -> Disco IErr Value |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You said you weren't happy with the oeisLookup
implementation but it seems fine to me. What were you not happy with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's mostly that this is my first Haskell PR :-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fair enough. =)
@byorgey all great suggestions, I'll push some changes shortly. Thanks for the review! What are your thoughts on |
It's true that having |
@byorgey pushed some changes (squashed) |
Looks great, thanks! |
oeisLookup
implementation, suggestions for cleanup welcome!I'll pull in style changes from Restyle add lookupSequence, extendSequence for OEIS access #203 into this branch after reviewSee also: #189