Skip to content

Latest commit

 

History

History
117 lines (86 loc) · 4.39 KB

README.md

File metadata and controls

117 lines (86 loc) · 4.39 KB

Concept-C#

We've forked Roslyn to add concepts: superpowered interfaces for C# extension methods, inspired by Haskell typeclasses, Scala implicits, and Rust traits. Concepts are brought to you by @crusso and @MattWindsor91.

Here's a simple example of concepts:

public concept CMonoid<T>
{
    T Append(this T x, T y);  // extension methods
    T Zero { get; }           // properties on types!
}

public instance Monoid_Ints : CMonoid<int>
{
    int Append(this int x, int y) => x + y;
    int Zero => 0;
}

public static T Sum<T, implicit M>(T[] ts) where M : CMonoid<T>
{
    T acc = M.Zero;
    foreach (var t in ts) acc = acc.Append(t);
    return acc;
}

Sum(new int[] { 1, 2, 3, 4, 5 });  // 15

For a deeper introduction to concepts, see concepts\docs\tour.md.

Health Warnings

This is an experimental prototype. It will behave oddly, crash, eat your laundry, set fire to your cats, and otherwise ruin your day. In particular, Visual Basic doesn't support concepts, and probably doesn't work at all.

Do not report bugs in this fork to the dotnet/Roslyn team, unless you can reproduce them on normal Roslyn too.

How to Build

The build process is the same as Roslyn's build process, so we recommend you follow their existing documentation.

How to Test

If you have Visual Studio, the easiest way to test Concept-C# is to use Roslyn's CompilerExtension and VisualStudioSetup.Next projects to install the Concept-C# versions of Roslyn internals into a testbed Visual Studio instance.

Otherwise, you can use Concept-C#'s csc.exe to compile programs with concepts. It can be slotted into msbuild using the /p:CscToolPath switch, for instance.

Warning

To use concepts, you must:

  • use the concepts feature flag;
    • For csc, use /features:concepts.
    • For msbuild, add <Features>concepts</Features> to the first PropertyGroup.
  • build and reference ConceptAttributes.dll.
    • The project for this is located in concepts\code\ConceptAttributes.

Examples

We have a large set of ready-to-build examples in the concepts\code\Concepts.sln solution. These include:

  • \ConceptLibrary\: a standard library for concepts, including a Haskell-style prelude and concepts for enumerating and converting to string;
  • \Features\: small testbeds for concept features;
  • \BeautifulDifferentiation\: an implementation of Conal Elliott's Beautiful Differentiation paper, using concepts for numeric abstraction;
  • \Quickhull\: an implementation of the Quickhull algorithm, using concepts for monoids and numeric abstraction;
  • \SerialPBT\: a simple property-based tester similar to Runciman et al.'s SmallCheck, using concepts to abstract over testable properties;
  • \TinyLINQ\: a prototype concept-based implementation of most of LINQ to Objects.

Documentation

Supporting documentation is included in the concepts\docs directory. This is usually in Pandoc-compatible Markdown-with-LaTeX.

Our general design (based on implementation ideas by Claudio Russo) is included in concepts\docs\concepts.md.

Further reading

  • The shapes proposal was based on an earlier version of Concept-C#, and recently we've been working to try align our feature set to it. There's a comparison between what we do and what Shapes does in concepts\code\ShapesComparison\.