digitalmars.D.learn - Compiler/Phobos/Types problem =?UTF-8?Q?=E2=80=94?= panic level due
- Russel Winder (50/50) May 05 2019 Hi,
- lithium iodate (13/23) May 05 2019 `recurrence` takes the `CommonType` of the initial values and
- Nicholas Wilson (3/30) May 05 2019 Yep https://run.dlang.io/is/XsLrRz works for me,
- Russel Winder (2/6) May 06 2019 Thanks people. I now have a working code. :-)
- John Colvin (5/12) May 06 2019 pretty please show people it with UFCS:
- Russel Winder (10/17) May 08 2019 Any particular reason for preferring this form over the original?
- Alex (3/14) May 08 2019 For example, It is more readable, as the order of execution is
- Russel Winder (11/27) May 08 2019 I think there is an individual element to this, and what people are
- John Colvin (3/14) May 09 2019 Not big benefit in this case, very big benefit with longer chains.
- Russel Winder (16/21) May 09 2019 John,
Hi, I had merrily asumed I could implement nth Fibonacci number with: takeOne(drop(recurrence!((a, n) =3D> a[n-1] + a[n-2])(zero, one), n)).f= ront where zero and one are of type BigInt, and n is of type size_t. However bot= h dmd and ldc2 complain saying: /usr/include/dmd/phobos/std/range/package.d(5770): Error: template std.bigi= nt.BigInt.opAssign cannot deduce function from argument types !()(immutable= (BigInt)) immutable, candidates are: /usr/include/dmd/phobos/std/bigint.d(178): std.bigint.BigInt.opAssig= n(T)(T x) if (isIntegral!T) /usr/include/dmd/phobos/std/bigint.d(194): std.bigint.BigInt.opAssig= n(T : BigInt)(T x) /usr/include/dmd/phobos/std/range/package.d(5770): Error: template std.bigi= nt.BigInt.opAssign cannot deduce function from argument types !()(immutable= (BigInt)) immutable, candidates are: /usr/include/dmd/phobos/std/bigint.d(178): std.bigint.BigInt.opAssig= n(T)(T x) if (isIntegral!T) /usr/include/dmd/phobos/std/bigint.d(194): std.bigint.BigInt.opAssig= n(T : BigInt)(T x) fibonacci.d(25): Error: template instance `fibonacci.declarative.recurrence= !((a, n) =3D> a[n - 1] + a[n - 2], immutable(BigInt), immutable(BigInt))` e= rror instantiating /usr/include/dmd/phobos/std/range/package.d(5720): Error: template std.bigi= nt.BigInt.opAssign cannot deduce function from argument types !()(immutable= (BigInt)) immutable, candidates are: /usr/include/dmd/phobos/std/bigint.d(178): std.bigint.BigInt.opAssig= n(T)(T x) if (isIntegral!T) /usr/include/dmd/phobos/std/bigint.d(194): std.bigint.BigInt.opAssig= n(T : BigInt)(T x) /usr/include/dmd/phobos/std/range/package.d(3177): Error: template instance= `std.range.primitives.isInputRange!(Recurrence!(__lambda2, immutable(BigIn= t), 2LU))` error instantiating fibonacci.d(25): Error: template std.range.drop cannot deduce function from= argument types !()(Recurrence!(__lambda2, immutable(BigInt), 2LU), immutab= le(ulong)), candidates are: /usr/include/dmd/phobos/std/range/package.d(3176): std.range.drop(R)= (R range, size_t n) if (isInputRange!R) I am now at the WTF stage =E2=80=93 how can I show this example on Thursday= in my DevoxxUK presentation?=20 I am close to giving up and imbibing of too much Pernod. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
May 05 2019
On Sunday, 5 May 2019 at 18:53:08 UTC, Russel Winder wrote:Hi, I had merrily asumed I could implement nth Fibonacci number with: takeOne(drop(recurrence!((a, n) => a[n-1] + a[n-2])(zero, one), n)).front where zero and one are of type BigInt, and n is of type size_t. However both dmd and ldc2 complain saying:[…]I am now at the WTF stage – how can I show this example on Thursday in my DevoxxUK presentation? I am close to giving up and imbibing of too much Pernod.`recurrence` takes the `CommonType` of the initial values and declares its internal state as an array of this type, however when at least one of the values is const or immutable, the `CommonType` is const too, or even immutable in the case when all values are immutable. The state being const/immutable means that the following step, initializing it, can't work, since, well, the array cannot be modified (hence the errors). I'd say this can be considered to be a bug with `recurrence`. You can solve this issue by constructing and passing mutable versions of `one` and `zero` to `recurrence`.
May 05 2019
On Sunday, 5 May 2019 at 19:18:47 UTC, lithium iodate wrote:On Sunday, 5 May 2019 at 18:53:08 UTC, Russel Winder wrote:Yep https://run.dlang.io/is/XsLrRz works for me, https://run.dlang.io/is/KxY0e9 doesn't.Hi, I had merrily asumed I could implement nth Fibonacci number with: takeOne(drop(recurrence!((a, n) => a[n-1] + a[n-2])(zero, one), n)).front where zero and one are of type BigInt, and n is of type size_t. However both dmd and ldc2 complain saying:[…]I am now at the WTF stage – how can I show this example on Thursday in my DevoxxUK presentation? I am close to giving up and imbibing of too much Pernod.`recurrence` takes the `CommonType` of the initial values and declares its internal state as an array of this type, however when at least one of the values is const or immutable, the `CommonType` is const too, or even immutable in the case when all values are immutable. The state being const/immutable means that the following step, initializing it, can't work, since, well, the array cannot be modified (hence the errors). I'd say this can be considered to be a bug with `recurrence`. You can solve this issue by constructing and passing mutable versions of `one` and `zero` to `recurrence`.
May 05 2019
On Sunday, 5 May 2019 at 19:34:05 UTC, Nicholas Wilson wrote:On Sunday, 5 May 2019 at 19:18:47 UTC, lithium iodate wrote:Thanks people. I now have a working code. :-)[...]Yep https://run.dlang.io/is/XsLrRz works for me, https://run.dlang.io/is/KxY0e9 doesn't.
May 06 2019
On Monday, 6 May 2019 at 13:05:27 UTC, Russel Winder wrote:On Sunday, 5 May 2019 at 19:34:05 UTC, Nicholas Wilson wrote:pretty please show people it with UFCS: recurrence!((a, n) => a[n-1] + a[n-2])(zero, one) .dropExactly(n) .frontOn Sunday, 5 May 2019 at 19:18:47 UTC, lithium iodate wrote:Thanks people. I now have a working code. :-)[...]Yep https://run.dlang.io/is/XsLrRz works for me, https://run.dlang.io/is/KxY0e9 doesn't.
May 06 2019
On Mon, 2019-05-06 at 15:53 +0000, John Colvin via Digitalmars-d-learn wrote:[=E2=80=A6] =20 pretty please show people it with UFCS: =20 recurrence!((a, n) =3D> a[n-1] + a[n-2])(zero, one) .dropExactly(n) .frontAny particular reason for preferring this form over the original? --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
May 08 2019
On Wednesday, 8 May 2019 at 11:53:34 UTC, Russel Winder wrote:On Mon, 2019-05-06 at 15:53 +0000, John Colvin via Digitalmars-d-learn wrote:For example, It is more readable, as the order of execution is unwinded.[…] pretty please show people it with UFCS: recurrence!((a, n) => a[n-1] + a[n-2])(zero, one) .dropExactly(n) .frontAny particular reason for preferring this form over the original?
May 08 2019
On Wed, 2019-05-08 at 11:56 +0000, Alex via Digitalmars-d-learn wrote:On Wednesday, 8 May 2019 at 11:53:34 UTC, Russel Winder wrote:I think there is an individual element to this, and what people are used to. However I have taken John's request and changed the line he wanted changed. --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.ukOn Mon, 2019-05-06 at 15:53 +0000, John Colvin via=20 Digitalmars-d-learn wrote:=20 For example, It is more readable, as the order of execution is=20 unwinded.[=E2=80=A6] =20 pretty please show people it with UFCS: =20 recurrence!((a, n) =3D> a[n-1] + a[n-2])(zero, one) .dropExactly(n) .front=20 Any particular reason for preferring this form over the=20 original?
May 08 2019
On Wednesday, 8 May 2019 at 11:53:34 UTC, Russel Winder wrote:On Mon, 2019-05-06 at 15:53 +0000, John Colvin via Digitalmars-d-learn wrote:Not big benefit in this case, very big benefit with longer chains. It reads in the order of operations, as opposed to inside out.[…] pretty please show people it with UFCS: recurrence!((a, n) => a[n-1] + a[n-2])(zero, one) .dropExactly(n) .frontAny particular reason for preferring this form over the original?
May 09 2019
On Thu, 2019-05-09 at 08:33 +0000, John Colvin via Digitalmars-d-learn wrote:[=E2=80=A6] =20 Not big benefit in this case, very big benefit with longer chains. =20 It reads in the order of operations, as opposed to inside out.John, Coming from a Haskell/Lisp background to declarative expression, I do not have a problem with the function application approach. However if the audience are more likely to understand the method application approach (and this is fundamentally a Java audience) then that is the way of should be shown. I showed the variant you suggested. :-) --=20 Russel. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D Dr Russel Winder t: +44 20 7585 2200 41 Buckmaster Road m: +44 7770 465 077 London SW11 1EN, UK w: www.russel.org.uk
May 09 2019