In PureScript, strings are treated as arrays of characters, which simplifies some operations but may not be as efficient for large strings or complex Unicode manipulations. Here’s a breakdown of the key differences and concepts:
PureScript uses String for string types, and they are inherently Unicode-aware.
The length function on a string returns the number of characters, not bytes.
PureScript doesn’t have a built-in concept of “runes”. Instead, we work with Char values, which represent Unicode code points.
To get the Unicode code points, we convert the string to an array of characters and then map over it with toCharCode.
Iteration over characters in a string is typically done using higher-order functions like traverse_ or by converting the string to an array of characters first.
PureScript doesn’t have mutable variables or traditional for-loops. Instead, we use recursion or higher-order functions for iteration.
The examineChar function demonstrates how to work with individual characters.
To run this program, you would typically compile it with the PureScript compiler and then run it using Node.js or in a browser environment, depending on your project setup.
This example demonstrates how PureScript handles strings and characters, which differs from some other languages in its functional and immutable approach.