Skip to content
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

Instance for Numeric.Natural #16

Open
dschrempf opened this issue Sep 26, 2022 · 1 comment
Open

Instance for Numeric.Natural #16

dschrempf opened this issue Sep 26, 2022 · 1 comment

Comments

@dschrempf
Copy link

Hi! I was wondering if we could provide an orphan instance for Numeric.Natural? At the moment, I am using something naive like:

fToMemoize :: Natural -> a
fToMemoize = ...

fToMemoizeI :: Integer -> a
fToMemoizeI = fToMemoize . fromIntegral

fMemoized :: Natural -> a
fMemoized = memoize fToMemoizeI . fromIntegral

I had a look at the definition of Natural, and it is either a simple WordXX, or a big natural. The big natural is, as far as I can see, similarly built as 'Integers, and could be converted to a list (like it is done for the Memoizableinstance ofInteger`). Could you please help out here? Thank you!

@jwaldmann
Copy link
Contributor

like this?

instance Memoizable Natural where
  memoize f = memoize (f . fromIntegral) . toInteger

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants