I have a class named “Person”
Person :: String -> String -> Int -> Gender -> Person
Goal:
To make a more general version of Person, the femalePerson by assigning Gender to Female.
What works:
Binding first N elements works:
let personsWithNameAlice = Person "Alice"
let personsWithNameAliceMcGee = Person "Alice" "McGee"
What doesn’t work:
let femalePerson = Person {gender = Female}
Question:
- How do i do THIS?
- How do i a bind a value to n-th element of any function where n != 0?
It’s just that i know i can write f(x,y,z) = g(x,y,z,5) in math and std::bind2nd(f, 8) in C++ so shouldn’t it be possible in Haskell?
You can do it with a lambda expression, given
you’d define
or, with arguments in the binding:
If you want to bind specifically the second parameter,
flipis the function you wantYou can use
flipto bind arguments in arbitrary positions, but that quickly becomes a hassle and unreadable: