Some supposed improvements of Idris language over Haskell:
Given two records:
record Account where
constructor MkAccount
accound_id : String
address : String
record Customer where
constructor MkCustomer
name : String
address : String
account : Account
Idris gives you a simple built-in syntax to update nested records:
update_billing_address : Customer -> String -> Customer
update_billing_address customer address =
record { account->address = address } customer
Similar Rust code:
struct Account {
accound_id: u64, // No string
address: String,
}
struct Customer {
name: String,
address: String,
account: Account,
}
fn main() {
let a1 = Account { accound_id: 1, address: "xx".into() };
let c1 = Customer { name: "nnn".into(), address: "yy".into(), account: a1 };
// You can't do this in Rust here:
let c2 = Customer { account: Account { accound_id: 2, ..a1 }, ..c1 };
// A Idris-inspired syntax:
let c2 = Customer { account.accound_id: 2, ..c1 };
}
Idris also allows to apply a function over a field in a nested record, like this (with the $= operator):
concat_billing_address : Customer -> String -> Customer
concat_billing_address customer complement =
record { account->address $= (++ complement) } customer
Something similar in Rust (currently not allowed):
let c2 = Customer { account.account_id: account.accound_id + 2, ..c1 };
The syntax shown here could be useful if you want to use Rust with immutable data, in a more functional style.