

Idris 0.9.15 released – partial evaluation and uniqueness types - logicchains
http://www.idris-lang.org/idris-0-9-15-released/

======
logicchains
Some highlights:

Uniqueness types[1], which are inspired by ownership types and borrowed
pointers in the Rust language, and should eventually be able to provide
compile-time guarantees that critical program fragments will never allocate.
If this was achieved, Idris would potentially be usable for tasks that
previously necessitated using either C, C++ or Rust.

Partial evaluation[2], which can also be used to improve performance by
specialising type classes and higher order functions. Another use is creating
speedy interpreters/EDSLs, with the one in [3] being competitive in speed with
Java in spite of only being an interpreter.

Uniqueness types can also be used for safe in-place updates of a
datastructure. The following map function, for instance, where UList is a
UniqueType, will be compiled to code that updates the list in-place, avoiding
allocating a new list:

umap : (a -> b) -> UList a -> UList b

    
    
        umap f [] = []
    
        umap f (x :: xs) = f x :: umap f xs
    

1\. [https://github.com/idris-lang/Idris-dev/wiki/Uniqueness-
Type...](https://github.com/idris-lang/Idris-dev/wiki/Uniqueness-Types)

2\. [https://github.com/idris-lang/Idris-dev/wiki/Static-
Argument...](https://github.com/idris-lang/Idris-dev/wiki/Static-Arguments-
and-Partial-Evaluation)

3\. [http://eb.host.cs.st-
andrews.ac.uk/writings/icfp10.pdf](http://eb.host.cs.st-
andrews.ac.uk/writings/icfp10.pdf)

~~~
simias
If I understand correctly Uniqueness Types cannot be used in place of regular
Types? That is, if one function takes regular Types you can't have it work on
an Uniqueness Type?

If so, doesn't that make Uniqueness Types very awkward to use?

~~~
edwinb
It's hard to write something that's generic over a uniqueness type and a
normal type, which is indeed a bit of a pain. It's not completely impossible:
we have a kind 'Type*' which covers both unique and normal types, which can be
used to make some polymorphic functions which preserve uniqueness, but that's
all at the minute.

On the other hand, I see them as something you use when you want more precise
control over memory management, control of in-place update and so on.

As ever, there's a trade off between efficiency and abstraction, which is
where the partial evaluator comes in. This is still experimental and we're
working on it, but I'm wondering if we can use partial evaluation to turn
nicely abstract high level code into something efficient based on uniqueness
types at run time.

~~~
simias
Thank you for both your answers.

I guess my main worry with this scheme would be fragmentation, having 3rd
party libraries not bothering using Type* where it makes sense and making it
very difficult to write code using uniqueness types. I guess I'll have to
learn me some Idris and see for myself, the language looks very interesting.

------
carloscm
This reminded me of ATS - [http://www.ats-lang.org/](http://www.ats-lang.org/)
Check also Chris Double blog -
[http://bluishcoder.co.nz/tags/ats/](http://bluishcoder.co.nz/tags/ats/)

ATS combines ML-style types, linear types, dependent types and theorem-
proving. Plus it compiles down to C, has pointers including (safe!) pointer
arithmetic, has trivial C interop, and doesn't have GC (alloc/free safety is
provided by the linear types, like with Rust lifetimes). It's a really
interesting beast and I hope I have more time in the future to dive into it.
Idris wins in the syntax department tho.

~~~
bjz_
> alloc/free safety is provided by the linear types, like with Rust lifetimes

Rust's move/ownership semantics are based on linear types, where as its
lifetimes are based on regions. ATS has linear types, but not regions.

------
joelthelion
If anyone wants to try Idris out, there is an Idris starter package for the
very neat Vindinium AI challenge:
[http://vindinium.org/starters](http://vindinium.org/starters)

