Dhall-lang: Add Text/split primitive

Created on 25 Jan 2019  路  2Comments  路  Source: dhall-lang/dhall-lang

It would be cool to have some way to do search + replace on Text values and the simplest way to do it I can think of is a Text/split primitive.

let split : Text -> Text -> List Text = \sep -> \input -> Text/split sep input

with this, replacing a character (or a longer sequence) can be defined in dhall (could be added to the prelude):

let replace = \(old : Text) -> \(new : Text) -> \(input : Text) ->
    prelude.`Text`.concatSep new (Text/split old input)

I don't have time right now to implement this myself, so I am opening this issue

Most helpful comment

I've been holding off as long as possible on standardizing support for parsing and introspection on Text values. The main reason is to catch more input failures at type-checking time rather than at run time (i.e. via Optional values). Also, I prefer requiring that the input is a more structured representation than a string in order to ensure that invalid inputs are unrepresentable

However, I do maintain a wiki page explaining how you can add your own built-ins if necessary here: https://github.com/dhall-lang/dhall-lang/wiki/Built-in-types,-functions,-and-operators

All 2 comments

I've been holding off as long as possible on standardizing support for parsing and introspection on Text values. The main reason is to catch more input failures at type-checking time rather than at run time (i.e. via Optional values). Also, I prefer requiring that the input is a more structured representation than a string in order to ensure that invalid inputs are unrepresentable

However, I do maintain a wiki page explaining how you can add your own built-ins if necessary here: https://github.com/dhall-lang/dhall-lang/wiki/Built-in-types,-functions,-and-operators

Yeah, I think the current design works well and I agree that this should be held off

Was this page helpful?
0 / 5 - 0 ratings