Implementing Haskell's Type-Level Quicksort in D

Meta jared771 at gmail.com
Mon Feb 10 09:12:05 PST 2014


I'm trying to write a D implementation of Haskell's "type level 
quicksort"[0], but I'm already running into problems with 
std.typecons.Typedef. I have tried to translate this Haskell code:

  data Zero
  data Succ a

  -- booleans
  data True
  data False

  -- lists
  data Nil
  data Cons a b

  -- shortcuts
  type One   = Succ Zero
  type Two   = Succ One
  type Three = Succ Two
  type Four  = Succ Three



To this code in D:

import std.typecons;

struct Zero {}
struct Succ(a) {}

struct True  {}
struct False {}

struct Nil {}
struct Cons(a, b) {}

alias One = Typedef!(Succ!Zero);
alias Two = Typedef!(Succ!One);
alias Three = Typedef!(Succ!Two);
alias Four = Typedef!(Succ!Three);


void main()
{
	auto test = Four();
}

But I'm getting a compiler error when actually trying to 
construct a Four:

Error: template std.typecons.Typedef!(Succ!(Zero), 
Succ()).Typedef.Proxy!(Typedef_payload).opCall does not match any 
function template declaration.

Candidates are:
std.typecons.Typedef!(Succ!(Zero), 
Succ()).Typedef.Proxy!(Typedef_payload).opCall(this X, 
Args...)(auto ref Args args)



I tried defining a static opCall in the Zero struct that doesn't 
take any arguments, but that didn't make a difference. I'm 
guessing this is a bug with Typedef, but does anyone have an idea 
of where that bug might be?




1. 
http://www.haskell.org/haskellwiki/Type_arithmetic#An_Advanced_Example_:_Type-Level_Quicksort


More information about the Digitalmars-d-learn mailing list