question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

implement Enum Text and lowercase, uppercase conversion.

See original GitHub issue

Can we add to the stdlib:

ub : Int
ub = 1114112 -- = 17 * 65,536

cplToI : [Int] -> Int
cplToI l = fst $ foldl u (0, 1) l
  where u (a, p) i = (a + i * p, p * ub)

iToCplAcc : [Int] -> Int -> [Int]
iToCplAcc acc i =
  let d = i / ub in
  if d == 0 then
    i :: acc
  else
    iToCplAcc (i::acc) (i - d * ub)

iToCpl : Int -> [Int]
iToCpl = iToCplAcc []

instance Enum Text where
  fromEnum = cplToI . toCodePoints
  toEnum = fromCodePoints . iToCpl

my goal is to also add

ia = fromEnum "a"
iz = fromEnum "z"

iA = fromEnum "A"
iZ = fromEnum "Z"

toUpperAsciiChar : Text -> Text
toUpperAsciiChar c
  | ia <= ic && ic <= iz = toEnum (ic + (iA - ia))
  | otherwise = c
      where ic = fromEnum c

toLowerAsciiChar : Text -> Text
toLowerAsciiChar c
  | iA <= ic && ic <= iZ = toEnum (ic - (iA - ia))
  | otherwise = c
      where ic = fromEnum c

toUpper : Text -> Text
toUpper = implode . fmap toUpperAsciiChar . explode

toLower : Text -> Text
toLower = implode . fmap toLowerAsciiChar . explode

But if there are primitives that we can leverage that accomplish toLower and toUpper better (ala explode), that would be great.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
remyhaemmerle-dacommented, Oct 6, 2021

@leonidr-da I have never said, there is no legitimate use cases 😉. I even supported you for adding some functions to the standard library. I am just a bit reluctant to add new LF primitives each time we find Daml too slow.

On the one hand, adding primitives does not solve the intrinsic problem of slowness, but just circumvent it in some particular use cases, while increasing maintenance cost. On the other hand, solving really Daml slowness will require rewriting the interpreter, the fewer primitives we have the easier this task will be.

1reaction
cocreaturecommented, Oct 11, 2021

Adding it to the standard library seems very reasonable to me. I agree with @remyhaemmerle-da that we should be careful wtr to primitives. I do expect that we’ll want to expand the set of Text primitives at some point but I’d rather do that in one go accompanied by design & benchmark work to only add the ones that really pay off instead of adding more and more primitives over time.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to store enum type as lowercase string? - Stack Overflow
Your code works for me. toString and getStatus both returns lowercase strings. · @Bittenus, I try to store enum in the database as...
Read more >
Converting Strings to Enums in Java | Baeldung
A quick and practical guide to converting strings to enums in Java.
Read more >
Enum values are converted to uppercase #310 - GitHub
Hi, guys. I noticed that when posting variables, enums are auto-converted to uppercase. Variables = new { qr_type = qrType } public enum...
Read more >
Enums | Dev Cheatsheets - Michael Currin
Use uppercase letters for your enums - they are global constants which have usable values. They are more than just types, which use...
Read more >
Java - convert String to Enum object - Dirask
In java we can simply convert String to enum by using .valueOf() method on our Enum class. ... Note: We need to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found