'Splitting a string in dhall

I'm playing with dhall and wondered how I can implement a string splitting function of the form

λ(text: Text) -> λ(delimiter: Text) -> List Text

However, it appears dhall has no concept/type to represent individual characters. and there's no such function in the Prelude.

The only thing you can do with Text values is concatenate them

So... is it even possible?



Solution 1:[1]

This is not currently possible with the existing Dhall built-in functions. The Text type is conceptually opaque, similar to Double. The only thing you can do with values of type Text is concatenate them, but you cannot introspect, parse, or compare them for equality.

My original rationale for limiting Text in this way is that the language encourages upstreaming strongly typed representations into its inputs. For example, instead of splitting the string, require that the string has already been split (i.e. expect an input of type List Text instead of Text). However, this could change at some point because the standard is not set in stone and evolves over time through the process outlined here:

Also, even without making changes to the language you can still experiment by extending the language with your own built-ins using the Haskell API by following this guide:

Edit: One thing changed since writing this comment, which is that the language now supports a Text/replace builtin, so even though you still can't split a string you can replace one delimiter with another one. For example:

? Text/replace " " "," "Foo Bar Baz"

"Foo,Bar,Baz"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1