1

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"
Ganesh Sittampalam
  • 28,821
  • 4
  • 79
  • 98
Thomas
  • 366
  • 6
  • 19
  • 2
    `String` is just syntactic sugar for `[Char]`. – jub0bs Oct 05 '14 at 14:52
  • i know, but still not helps, if they were eqvivalent semantically too then the code would produce "ssssss" – Thomas Oct 05 '14 at 15:15
  • 3
    Is this question tagged right? At the moment it's tagged `haskell` and `functional-programming`. I don't know Clean, but in haskell it would be `arrayLower xs = map toLower xs` and there would be no need for `stringLower`. – Gareth Charnock Oct 05 '14 at 15:31
  • Are you getting an error or incorrect output? What is the error if it's an error, and what is the output if you're getting incorrect output? – David Young Oct 05 '14 at 15:34
  • almost, there is not tag for Clean, but Clean is very similar to Haskell – Thomas Oct 05 '14 at 17:09
  • the output is "", instead of "ssssss", that is my problem – Thomas Oct 05 '14 at 17:10
  • unfortunately toLower is not working for String only just for Char – Thomas Oct 05 '14 at 17:14

1 Answers1

4

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} 
molbdnilo
  • 64,751
  • 3
  • 43
  • 82
  • it's still not working: Type error [Interleave.icl,6,stringLower]: near map : cannot unify types: String [v0] – Thomas Oct 05 '14 at 17:19
  • @GaborToth How about this one? (Edited.) – molbdnilo Oct 05 '14 at 20:07
  • i see, but the output is still "" :(, the complier says: Warning [Interleave.icl,9,stringLower]: alternative will never match – Thomas Oct 06 '14 at 05:44
  • @GaborToth Then you didn't remove the `stringLower _ = ""` case. – molbdnilo Oct 06 '14 at 06:45
  • module Something import StdEnv, StdLib arrayLower :: [Char] -> [Char] arrayLower [x:xs] = map toLower [x:xs] stringLower :: String -> String stringLower s = toString (arrayLower s) Start:: String Start = stringLower "SSSsss" – Thomas Oct 07 '14 at 10:43
  • so i removed, and i get: Type error [Something.icl,8,stringLower]:"argument 1 of arrayLower" cannot unify types: [Char] String – Thomas Oct 07 '14 at 10:43
  • @GaborToth `[Char]` is a list, not a `String`. I looked through the manuals and edited the answer. – molbdnilo Oct 07 '14 at 11:35