Search code examples
functional-programmingclean-language

How to lowercase a string in CLEAN


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"

Solution

  • 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}