-
Notifications
You must be signed in to change notification settings - Fork 37
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
Draft for add bindings for numeric typeclasses #339
base: master
Are you sure you want to change the base?
Conversation
I think there's some confusion here: record Real (a : Set) : Set where
field
toRational : a -> Rational
open Real ⦃...⦄ public
{-# COMPILE AGDA2HS Real existing-class #-} However, this first requires the addition of the |
Thanks for your helpful feedback, @jespercockx. I am trying to define Rational: {-# OPTIONS --no-auto-inline #-}
module Haskell.Prim.Rational where
open import Haskell.Prim.Integer
--------------------------------------------------
-- Definition
-- | Rational numbers, with numerator and denominator of some 'Integral' type.
data Ratio (a : Set) : Set where
:% : a → a → Ratio a
numerator : Ratio a → a
denominator : Ratio a → a
-- | Arbitrary-precision rational numbers, represented as a ratio of
-- two 'Integer' values. A rational number may be constructed using
-- the '%' operator.
Rational : Set
Rational = Ratio Integer But I get the error:
It seems like the type checker expects that there should be a Integer datatype, which is missing in Prim/Integer.agda. Another problem I encountered is that I don't know how to define instances of Integral. For example: iIntegralInt : Integral Int
iIntegralInt._quot_ n d = ?
iIntegralInt._rem_ n d = ?
iIntegralInt._div_ n d = ?
iIntegralInt.quotRem n d = ?
iIntegralInt.toInteger x = toInteger x This seems to require arithmetic operations that are lacking in Int. |
It seems like Also note that |
Quotient and remainder are defined in the standard library at https://github.com/agda/agda-stdlib/blob/d3c50376c14a20604940c5f6694a5bb2602d34a7/src/Data/Integer/Base.agda#L283-L294, so you could try to port the definitions from there to the |
See #262
cc @jespercockx
This is my first PR to agda2hs. I am also new to Agda in general. This draft is a way of showing what I currently have done.
I tried to follow the templates of other numeric types, but at the moment I don't know how to continue further. I'd like to receive comments on how to improve.
I looked at the following typeclasses in Haskell:
https://hackage.haskell.org/package/planet-mitchell-0.0.0/docs/Numeric-Floating.html#t:Floating
https://hackage.haskell.org/package/base-4.20.0.1/docs/Prelude.html#t:Fractional
https://hackage.haskell.org/package/planet-mitchell-0.0.0/docs/Numeric-RealFrac.html#g:2
https://hackage.haskell.org/package/planet-mitchell-0.0.0/docs/Numeric-RealFloat.html#v:encodeFloat
I have trouble with defining the types for Real, Integral and Fractional. I also don't know how to specify a pair (e.g. (Int, Realfrac) ) as a return type of a function in Agda.