How to lowercase a string in CLEAN

275 views Asked by At

I have a problem in CLEAN, how can I make lowercase all letter in a string? I can do it through an char array, but i need to do it with a string too. I have the code below so far:

module Something

import StdEnv, StdLib

arrayLower:: [Char] -> [Char]
arrayLower[x:xs] = (map toLower [x:xs]) 


stringLower:: String -> String
stringLower_ = ""
stringLowers = toString (arrayLower s)

Start:: String     
Start = stringLower"SSSsss"
1

There are 1 answers

7
molbdnilo On BEST ANSWER

Your first case

stringLower _ = ""

means that stringLower applied to anything is the empty string.
I'm surprised that you didn't get a warning for the redundant second case.

A String is an array (unboxed, so it's a {#Char}), and you say that you already know how to do this with arrays, but your arrayLower is defined for lists of Char ([Char]), not arrays.

This, using an array comprehension, works for me:

stringLower :: String -> String
stringLower s = {toLower c \\ c <-: s}