Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Constants in Idris

Tags:

idris

What's an idiomatic way to define what we call a constant in other languages in Idris? Is it this?

myConstant : String
myConstant = "some_constant1"


myConstant2 : Int
myConstant2 = 123

If so, in REPL I get an exception after declaration:

 (input):1:13: error: expected: "$",
like image 347
Jodimoro Avatar asked Oct 19 '25 04:10

Jodimoro


2 Answers

Yes, it is an idiomatic way of defining constants in Idris (in source files).

However, when binding a name in REPL, you need to use the :let directive with explicit type annotations like this:

Idris> :let myConstant : String; myConstant = "some_constant1"

or sometimes Idris is able to infer the type:

Idris> :let myConstant = "some_constant1"

It is described here.

like image 141
Anton Trunov Avatar answered Oct 22 '25 05:10

Anton Trunov


Nothing special in declaring global constants. The way you do it is the ok way.

If so, in REPL I get an exception after declaration:

Which version of Idris are you using? On 1.0 everything works fine for me. How do you declare variables? In file and than you're loading file in REPL?

like image 32
Shersh Avatar answered Oct 22 '25 03:10

Shersh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!