0

Does Idris have value types?

The term "value type" is a bit ambiguous, but I don't know a better one.

What I mean is: Is an array/struct of structs really always an array/struct of pointers (as in Java, and unlike C# and C++)?

Shersh
  • 9,019
  • 3
  • 33
  • 61
MWB
  • 11,740
  • 6
  • 46
  • 91

2 Answers2

3

Regarding Semantics

Value and reference types need a distinction only because of mutation. But Idris is purely functional.

Regarding Runtime Performance

"Value" types as in dotnet are usually referred to as "unboxed" in the Idris community.

AFAIK Idris does not yet support the coder's ability to declare a type unboxed. This may change in time as the language design seems to care about runtime performance.

Even if the language does not support explicit unboxing, the compiler may still do it. For example : if the runtime representation of the immutable value of a type is not bigger then that of a pointer then it is better to not box it. Note : the boxed status does not have to be decided by type. It is possible to unbox values of a type for general [immutable] usage and box some mutable usage of it.

The Idris language also has some advantage compared to dotnet regarding performance :

  • It does not have null value.
  • It has uniqueness type [in experimental stage].

The Idris back-ends are immature yet, they can be expected to miss even some basic optimization. If you are considered about runtime performance so much then now is too early to adopt Idris [though Haskell may still be a good choice]. However the language is designed with performance in mind, and i expect it to have better performance than dotnet in long time.

libeako
  • 2,324
  • 1
  • 16
  • 20
  • `though Haskell may still be a good choice` -- all those "high performance Haskell" examples are written with the sole purpose to mislead gullible people. If you actually look at the code, it's totally unsafe (worse than C) pointer salad. – MWB Jul 13 '17 at 20:57
  • 4
    @MaxB People use Haskell not because of it's performance (though it's very good compared to Python, PHP and even Java). You most likely can't beat C++ at raw CPU performance. But CPU performance usually means nothing when you application reads files, send requests to other machines or even to Internet. People use Haskell to not suffer from unbearable pain of programming on not-so-well-designed PLs. People use Haskell to keep themselves sane and sleep at nights instead of writing tests and debugging. – Shersh Jul 13 '17 at 22:02
  • 3
    @MaxB: You don’t have to go into “super-unsafe pointer salad” to be fast… – Ry- Jul 14 '17 at 04:41
  • @MaxB some benchmarks Haskell vs Java w/o «super-unsafe pointer salad»: http://benchmarksgame.alioth.debian.org/u64q/haskell.html – Shersh Jul 14 '17 at 09:04
  • @Shersh `"performance very good compared to Java"` & `" w/o «super-unsafe pointer salad»`" -- one of these is a lie... clicks on benchmarks ... GHC is slower in almost all benchmarks. in one of them it's **7x slower**. If you were honest, you'd admit that your claims were an intentional lie, but IME Haskell advocates rarely are. – MWB Jul 14 '17 at 09:46
  • @Ryan `You don’t have to go into “super-unsafe pointer salad” to be fast…` -- I agree (unless of course you are using Haskell) – MWB Jul 14 '17 at 09:57
  • @MaxB Those benchmarks code is not very good. In that benchmark that **7x** slower person didn't use fast data structures, he basically choose two slowest candidates :( Probably, he is not very smart. There exist modern and simpler way to achieve much better performance. If you were truly interested in truth you would dive into details, tried to implement by your own for your problem, ask on Reddit about benchmark result, see what's went wrong. On every language you can write _almost similar solutions_ which dramatically differs in performance. – Shersh Jul 14 '17 at 10:27
2

Since Idris will never mutate a value, all types are effectively value types. I'll bet this is the answer you want.

As for whether things are pointers under the hood: I know some values aren't (Int is a tagged value) and would bet that most are pointers in the C backend. This varies per backend.

eraserhd
  • 1,220
  • 8
  • 6
  • `I'll bet this is the answer you want.` -- Strange (Doesn't Idris have monads, which can modify array contents?). Anyway, my Q was not about that. The lack of value types is often cited as the source of Java's performance problems, and this lack is, partly, the reason Go was created. – MWB Jul 13 '17 at 01:05