Repository navigation
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.
It would be good to include some documentation and examples attached to these functions here, using ||| (documentation) and !!! (doctest/quickcheck) syntax.
|
|
||
| whnfOp OExtendSeq = arity1 "extendSequence" $ whnfV >=> oeisExtend | ||
| whnfOp OLookupSeq = arity1 "lookupSequence" $ whnfV >=> oeisLookup | ||
|
|
There was a problem hiding this comment.
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.
| 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.
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.
| 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.
The lambda could also be written vnum . (%1). Personally I find that easier to read, though tastes differ.
| @@ -0,0 +1,6 @@ | |||
| :load lib/oeis.disco | |||
There was a problem hiding this comment.
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.
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.
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.
I think it's mostly that this is my first Haskell PR :-)
|
@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! |
oeisLookupimplementation, 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