Re: [racket-users] Defining algebraic data types?

2018-02-06 Thread HiPhish
That makes perfect sense, thank you. On Tuesday, February 6, 2018 at 12:43:07 AM UTC+1, Sam Tobin-Hochstadt wrote: > The problem is that the definition of `(Dual-Number N)` includes `N`, > and therefore > > (Dual-Number (Dual-Number String)) might either be a (D (D "x" "y") (D > "x" "y")) or

Re: [racket-users] Defining algebraic data types?

2018-02-05 Thread Sam Tobin-Hochstadt
On Mon, Feb 5, 2018 at 6:36 PM, HiPhish wrote: > Why would that be a problem? The caller has to provide a function for > "adding" > and "multiplying" an N, and as long as I define what it means to multiply > and > add strings it shouldn't matter that I'm using a dual

Re: [racket-users] Defining algebraic data types?

2018-02-05 Thread HiPhish
Why would that be a problem? The caller has to provide a function for "adding" and "multiplying" an N, and as long as I define what it means to multiply and add strings it shouldn't matter that I'm using a dual number where both components are strings. But I think this is a case of the

Re: [racket-users] Defining algebraic data types?

2018-02-05 Thread Sam Tobin-Hochstadt
I'm not sure how the "If" got there. But to say more, consider your function: (: dual-* (∀ (N) (→ (Dual-Number N) (Dual-Number N) (→ N N N) (→ N N N) (Dual-Number N (define (dual-* d1 d2 * +) (cond [(D? d1) (D (D-real d1) (D-dual d1))] [else (D d1

Re: [racket-users] Defining algebraic data types?

2018-02-05 Thread HiPhish
Did your email get cut off? On Monday, February 5, 2018 at 6:00:05 PM UTC+1, Sam Tobin-Hochstadt wrote: > > This is an unfortunately common pitfall -- if you instantiated N with > something that includes a dual number, then the type error would be > pointing to a real bug. If > > Sam > --

Re: [racket-users] Defining algebraic data types?

2018-02-05 Thread Sam Tobin-Hochstadt
This is an unfortunately common pitfall -- if you instantiated N with something that includes a dual number, then the type error would be pointing to a real bug. If Sam On Feb 5, 2018 7:26 AM, "HiPhish" wrote: > Thank you for your answer, Sam. > > 1) does not really

Re: [racket-users] Defining algebraic data types?

2018-02-05 Thread HiPhish
Thank you for your answer, Sam. 1) does not really capture it, and 2) is a proof of concept that hasn't been updated in almost a year. But it did give me a good idea: use Typed Racket and have the type system work for me. (struct (N) D ([real : N] [dual : N])) (define-type (Dual-Number N)

Re: [racket-users] Defining algebraic data types?

2018-02-04 Thread Sam Tobin-Hochstadt
A few answers: 1. Use struct subtyping to give a type that includes both kinds: (struct dual ()) (struct quaternion dual (scalar vector)) (struct dual-quaternon dual (real dual)) 2. Use a library that supports algebraic data types, such as

[racket-users] Defining algebraic data types?

2018-02-04 Thread HiPhish
Hell Racketeers, I am trying to write an implementation of the mathematical concept of dual quaternions in Racket. Dual quaternions are an algebraic type and there are several equally valid way to look at them. Let me give some background first. A dual number (a + bε) is similar to a complex