Re: Algebra With Types

2017-04-24 Thread David Sanders via Digitalmars-d-learn

On Friday, 21 April 2017 at 20:49:27 UTC, Meta wrote:

On Friday, 21 April 2017 at 18:54:38 UTC, David Sanders wrote:

[...]


As an aside, there's a less convoluted way to do type-level 
arithmetic which is IMO also more concise and looks nicer. You 
don't have to mess around with Algebraic at all:


struct Zero;

struct Succ(N);

alias One = Succ!Zero;

alias Pred(N: Zero)= Zero;
alias Pred(N: Succ!Np, Np) = Np;

alias Add(N1: Zero, N2: Zero) = Zero;
alias Add(N1,   N2: Zero) = N1;
alias Add(N1: Zero, N2)   = N2;
alias Add(N1,   N2)   = Add!(Succ!N1, Pred!N2);

void main()
{
static assert(is(Pred!One == Zero));
static assert(is(Succ!One == Succ!(Succ!Zero)));

static assert(is(Add!(Zero, Zero) == Zero));
static assert(is(Add!(Zero, One) == One));
static assert(is(Add!(One, Zero) == One));
static assert(is(Add!(One, One) == Succ!(Succ!(Zero;

alias Two = Succ!One;
static assert(is(Add!(One, One) == Two));
static assert(is(Add!(One, Two) == 
Succ!(Succ!(Succ!Zero;


static assert(is(Sub!(Zero, Zero) == Zero));
static assert(is(Sub!(One, Zero) == One));
static assert(is(Sub!(Zero, One) == Zero));
static assert(is(Sub!(Two, One) == One));
static assert(is(Sub!(One, Two) == Zero));
}

Implementing Mul, Div and the integer set is an exercise left 
to the reader.


What you've implemented is similar to the Church encoding for 
natural numbers. I'm not trying to encode natural numbers.


I'm trying to investigate the algebra of "adding", "multiplying", 
and "raising to a power" various data types. Adding the int type 
with the char type corresponds to Algebraic!(int, char). 
Multiplying the int type by the char type corresponds to 
Tuple!(int, char). Raising the int type to the char type 
corresponds to a function that accepts a char and returns an int. 
See the blog post in my original forum post for examples.


Thanks,
Dave


Re: COM Expertise needed: COM Callbacks

2017-04-24 Thread Nierjerson via Digitalmars-d-learn

On Monday, 24 April 2017 at 17:31:09 UTC, MGW wrote:

On Monday, 24 April 2017 at 00:55:45 UTC, Nierjerson wrote:

Still trying to get the com automation code working. This is a


Please, use ZIP for archive.


http://s000.tinyupload.com/index.php?file_id=67286353487198133918


Re: COM Expertise needed: COM Callbacks

2017-04-24 Thread MGW via Digitalmars-d-learn

On Monday, 24 April 2017 at 00:55:45 UTC, Nierjerson wrote:

Still trying to get the com automation code working. This is a


Please, use ZIP for archive.


Re: GC: Understanding potential sources of false pointers

2017-04-24 Thread Nick Sabalausky (Abscissa) via Digitalmars-d-learn

On 04/22/2017 08:56 AM, Kagamin wrote:

.rdata is fine, but afaik you have only strings there, the rest - .data,
.bss, .tls will suffer the same issue.


I don't know anything about the various object file sections. :/


How to overload member function pointer and a regualr member function

2017-04-24 Thread ParticlePeter via Digitalmars-d-learn

I would like to have this kind of struct:

struct Foo {
  private int i;
  void function( int i, float f ) bar;  // will be defined at 
runtime

  void bar( float f ) {
bar( i, f );
  }
}

But apparently the function pointer and the member function 
cannot have the same name: Error: function main.Foo.bar conflicts 
with variable main.Foo.bar ...


I tried with an inner struct:
struct Foo {
  private int i;
  void function( int i, float f ) bar;  // will be defined at 
runtime

  private struct Inner {
void bar( float f ) {
  bar( i, f );
}
  }
  Inner inner;
}

But this time I get following error:
Error: need 'this' for 'i' of type 'int'

What does this message tell me? Should the inner struct not be 
able to access Foo.i?


How else can I get the required behavior?

I would prefer to avoid another indirection like this:
struct Foo {
  private int i;
  void function( int i, float f ) bar;  // will be defined at 
runtime

  void baz( float f ) {
bar( i, f );
  }
  void baz( int ii, float f ) {
bar( ii, f );
  }
}



Re: The app hanging after reach 1750MB of RAM

2017-04-24 Thread Suliman via Digitalmars-d-learn
The problem is solved. See for more detail 
https://github.com/mysql-d/mysql-native/issues/104


Re: Compile time foreach with switch

2017-04-24 Thread Nick Treleaven via Digitalmars-d-learn

On Saturday, 22 April 2017 at 11:56:31 UTC, Nick Treleaven wrote:

If I compile the above I get:
Deprecation: switch case fallthrough - use 'goto default;' if 
intended


IMO the compiler should issue this warning with the OP's code.


https://issues.dlang.org/show_bug.cgi?id=7390#c4