The Artima Developer Community
Sponsored Link

Heron-Centric: Ruminations of a Language Designer
A Problem involving the Syntax of Concepts in Heron
by Christopher Diggins
November 5, 2005
Summary
A concept is a description of a type, including functions signatures, preconditions, postconditions, invariants, and member types. In C++ it is an abstract idea, but in the next Heron it will exist as a construct. There is one small problem with the syntax when writing function signatures which use concepts.

Advertisement

Here are some examples of Heron concepts from the next version of the Heron standard library, which I am currently working on:

  concept Stack {
    refines  {
      Container;
    }
    signature {
      is_empty() : bool;
      push(element x);
      pop() : element;
    }
  }

  concept Container {
    types {
      Value element;
    }
    signature {
      for_each(Functor f);
    }
  }
The above code is hopefully self explanatory for most Java/C++ programmers, though I would be happy to explain anything which isn't clear.

In Heron you will be able to write a function using concepts as parameters instead of actual types as follows:

  fubar(Stack x, Stack y) {... }
The problem occurs when you want the two parameter types to be equivalent. A concept can match any type, so two completely different types can be passed to fubar as long as they model a stack concept. So what syntax should I use to express that I want the two parameter types to match? Here are some ideas:
  fubar(Stack x, y) { ... } 

  fubar(Stack x, x::self y) { ... } 

  fubar[Stack T](T x, T y) { ... } 

  fubar(Stack x, type[x] y) { ... } 
Which of these do you prefer? Any other suggestions?

Talk Back!

Have an opinion? Readers have already posted 27 comments about this weblog entry. Why not add yours?

RSS Feed

If you'd like to be notified whenever Christopher Diggins adds a new entry to his weblog, subscribe to his RSS feed.

About the Blogger

Christopher Diggins is a software developer and freelance writer. Christopher loves programming, but is eternally frustrated by the shortcomings of modern programming languages. As would any reasonable person in his shoes, he decided to quit his day job to write his own ( www.heron-language.com ). Christopher is the co-author of the C++ Cookbook from O'Reilly. Christopher can be reached through his home page at www.cdiggins.com.

This weblog entry is Copyright © 2005 Christopher Diggins. All rights reserved.

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use