简体   繁体   中英

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"

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} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM