Generics in PureScript
In PureScript, we use a different approach to generics compared to Go. Here are some key differences:
PureScript uses parametric polymorphism, which is similar to generics in other languages.
Instead of using a
comparable
constraint, we use theEq
typeclass to ensure that values can be compared for equality.PureScript doesn’t have mutable structures, so our
List
implementation is immutable.We use
Maybe Int
instead of returning -1 for not found cases, which is a more idiomatic approach in functional programming.PureScript uses
forall
to explicitly declare type variables in type signatures.
To run this program, you would typically compile it with the PureScript compiler and then run it with Node.js:
Note that the exact output format might differ slightly from the Go version due to PureScript’s data representations.