Re: Natural number comparisons with evidence

2018-05-24 Thread Joe Hendrix
To throw out additional related work, I had a need for runtime values that capture type-level naturals. It’s used primarily for representing the widths in a type-safe bitvector formulas. The code is a few years old, but publicly available here: https://github.com/GaloisInc/parameterized-uti

Re: Natural number comparisons with evidence

2018-05-24 Thread Conal Elliott
Oh, yes---`sameNat` is indeed quite similar to my `compareEv`. I hadn't noticed. Thanks, Simon. On Thu, May 24, 2018 at 2:30 PM, Simon Peyton Jones wrote: > I see this in GHC.TypeNats > > *sameNat ::* *(KnownNat a, KnownNat b) =>* > > * Proxy a -> Proxy b -> Maybe (a :~: b)* > > *sameN

RE: Natural number comparisons with evidence

2018-05-24 Thread Simon Peyton Jones via Glasgow-haskell-users
I see this in GHC.TypeNats sameNat :: (KnownNat a, KnownNat b) => Proxy a -> Proxy b -> Maybe (a :~: b) sameNat x y | natVal x == natVal y = Just (unsafeCoerce Refl) | otherwise= Nothing The unsafeCoerce says that sameNat is part of the trusted code base. And inde

Re: Natural number comparisons with evidence

2018-05-24 Thread Conal Elliott
I'm glad to know. Thanks for the endorsement, Richard. On Thu, May 24, 2018 at 1:05 PM, Richard Eisenberg wrote: > Just to add my 2 cents: I've played in this playground and used the same > structures as David. I second his suggestions. > > Richard > > > On May 24, 2018, at 3:54 PM, Conal Elliot

Re: Natural number comparisons with evidence

2018-05-24 Thread Richard Eisenberg
Just to add my 2 cents: I've played in this playground and used the same structures as David. I second his suggestions. Richard > On May 24, 2018, at 3:54 PM, Conal Elliott wrote: > > Great! Thanks for the suggestion to use type equality and coerced `Refl`. - > Conal > > On Thu, May 24, 201

Re: Natural number comparisons with evidence

2018-05-24 Thread Conal Elliott
Great! Thanks for the suggestion to use type equality and coerced `Refl`. - Conal On Thu, May 24, 2018 at 10:43 AM, David Feuer wrote: > On Thu, May 24, 2018, 1:03 PM Conal Elliott wrote: > >> Thanks for this suggestion, David. It seems to work out well, though I >> haven't tried running yet. >

Re: Natural number comparisons with evidence

2018-05-24 Thread David Feuer
On Thu, May 24, 2018, 1:03 PM Conal Elliott wrote: > Thanks for this suggestion, David. It seems to work out well, though I > haven't tried running yet. > > > unsafeDict :: Dict c > > unsafeDict = unsafeCoerce (Dict @ ()) > > > > unsafeSatisfy :: forall c a. (c => a) -> a > > unsafeSatisfy z | Di

Re: Natural number comparisons with evidence

2018-05-24 Thread Conal Elliott
where `Dict` is from Ed Kmett's constraints library ( https://hackage.haskell.org/package/constraints). On Thu, May 24, 2018 at 10:03 AM, Conal Elliott wrote: > Thanks for this suggestion, David. It seems to work out well, though I > haven't tried running yet. > > > unsafeDict :: Dict c > > unsa

Re: Natural number comparisons with evidence

2018-05-24 Thread Conal Elliott
Thanks for this suggestion, David. It seems to work out well, though I haven't tried running yet. > unsafeDict :: Dict c > unsafeDict = unsafeCoerce (Dict @ ()) > > unsafeSatisfy :: forall c a. (c => a) -> a > unsafeSatisfy z | Dict <- unsafeDict @ c = z Now we can define `compareEv`: > compareE