Variables in Idris
In Idris, variables are explicitly declared and used by the compiler to check type-correctness of function calls.
In Idris, variables are immutable by default, which is different from Go. The var
keyword is not used in Idris; instead, we use let
to declare variables.
Idris has strong type inference, so we don’t always need to specify types explicitly. However, we can add type annotations when needed.
Unlike Go, Idris doesn’t have a shorthand syntax like :=
for declaring and initializing variables. All variable declarations use let
.
To run this program, you would typically save it in a file with a .idr
extension (e.g., variables.idr
), and then use the Idris compiler to compile and run it:
In Idris, the concept of zero-values is replaced by default values for types. For example, the default value for Integer
is 0, for Bool
it’s False
, and for String
it’s an empty string.
Idris is a purely functional language with dependent types, which makes it quite different from Go in many aspects. The examples here have been adapted to fit Idris’ paradigm while trying to maintain the spirit of the original Go code.