archives

Scheme to be split into two languages

According to a draft statement, Scheme is to be split into a small and a large language, the small being designed for educators and "50-page purists", the large for "programmers, implementors".

The small language should remain true to the language design precepts found in the RnRS introduction ("Programming languages should be designed not by piling feature on top of feature, …").

But what about the large one? Will it drop continuations, become a Lisp-2, and challenge Common Lisp?

Function Interface Models for Hardware Compilation

Function Interface Models for Hardware Compilation. Dan Ghica.

The problem of synthesis of gate-level descriptions of digital circuits from behavioural specifications written in higher-level programming languages (hardware compilation) has been studied for a long time yet a definitive solution has not been forthcoming. The argument of this essay is mainly methodological, bringing a perspective that is informed by recent developments in programming-language theory. We argue that one of the major obstacles in the way of hardware compilation becoming a useful and mature technology is the lack of a well defined function interface model, i.e. a canonical way in which functions communicate with arguments. We discuss the consequences of this problem and propose a solution based on new developments in programming language theory. We conclude by presenting a prototype implementation and some examples illustrating our principles.

Ghica's work has been mentioned before, but not this particular article, which is a follow-up to that work. The paper touches on a number of common LtU topics: language design for hardware description, game semantics, Reynolds's SCI... I don't know much about hardware design, so I'd be interested to hear what people think.

Accumulating Types in C#

PartI:
------
Goul: I want to couple values together, in a statically strongly typed manner in C# (3.5) which has not an internal support for tuples in it's compiler; without defining new types.

Code:

namespace TypePiling
{
    using System.Text;
    using System;
    using System.IO;

    public static class Ex
    {
        public static Tuple<T, U> Glue<T, U>(this T t, U u)
        {
            return new Tuple<T, U> { First = t, Second = u };
        }
    }

    public class Tuple<T, U>
    {
        public T First { get; set; }
        public U Second { get; set; }

        public override string ToString()
        {
            var result = new StringBuilder();

            if (this.First != null) result.Append(string.Format("{0}", this.First.ToString()));
            if (this.Second != null) result.Append(string.Format(", {0}", this.Second.ToString()));

            return string.Format("{{ {0} }}", result.ToString().TrimStart(',').Trim());
        }
    }

    public static class Test
    {
        public static void Test1()
        {
            var i = 10;
            var g0 = i.Glue("Hi");
            var g1 = g0.Glue((byte)0xFF);
            var g2 = g1.Glue(100.0);
            var g3 = g2.Glue('A');
            var g4 = g3.Glue((float)1000);

            using (var sw = new StreamWriter("output.txt"))
            {
                sw.WriteLine(g0);
                sw.WriteLine(g1);
                sw.WriteLine(g2);
                sw.WriteLine(g3);
                sw.WriteLine(g4);

                sw.Flush();
            }

            System.Diagnostics.Process.Start("output.txt");
        }
    }
}

This code does what I want and g4 will be:
{ { { { { 10, Hi }, 255 }, 100 }, A }, 1000 }

This is my first problem; as you see I do that by put previous value and next value in a new container. So previous values are pile down in First. I want them be piled up in Second, so g4 should be:
{ 10, { Hi, { 255, { 100, { A, 1000 } } } } }

I it possible in C# 3.5? If not why?

Part II:
--------
In trying to answer Part I; I have wrote another Extension Method in class Ex:

public static Tuple<T, Tuple<U, V>> Glue<T, U, V>(this Tuple<T, U> t, V v)
{
    return new Tuple<T, Tuple<U, V>> { First = t.First, Second = t.Second.Glue(v) };
}

This should do it in a recursive manner. Let see what is the out put:
{ 10, Hi }
{ 10, { Hi, 255 } }
{ 10, { { Hi, 255 }, 100 } }
{ 10, { { { Hi, 255 }, 100 }, A } }
{ 10, { { { { Hi, 255 }, 100 }, A }, 1000 } }

What? What happened at step 3? Sure the compiler recognized { Hi, 255 } as Tuple<string, byte>; but why the first version of Glue executed not the second one, overloaded for a Tuple<T, U>?

Is this something about generics in C#?

After all implementing tuples in a statically strongly typed manner without compiler support (internal or by a macro system) is pointless, I know. But from this pointless try I have touched another problem: In C# I can not have real accumulated types, but just parametrized types which does not provide enough tools for composition.

Thanks in advance