Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Functional Programming

Name: Anonymous 2007-12-05 16:29

Hi /prog/, I needs help.

Could people give me some code in a functional language, specifically, I'd like some Haskell and OCaml. Lisp is also welcome. Other functional languages are also welcome (and appreciated), though I'm most interested in the mentioned ones.

The code snippet I'm looking for is to convert a string to uppercase, but I want the code to do this manually (so no calling some magical toupper function or whatever).
That means, this Haskell code is not valid, since it uses toUpper (though, if you define toUpper, I suppose I'll count it as valid).

import Data.Char
s = "alphaBETA"
upper = map toUpper s

Preferably I'd like code which does not use map or other such constructs (though if thats too dificult, then ignore this requirement). Also, if possible, I'd like code that converts the string both in place and by constructing a new string.


Basically, I want to see different approaches to doing this in different languages. All serious replies are appreciated. Trolls appreciated only if they make me laugh.

Name: Anonymous 2007-12-06 3:48

>>39
Well, no, not loops, but most algorithms still require them. Ok, in a functional language you would use recursion, or a construct like map, but they are still loops really. Thats what I meant by loops, I didn't mean you're standard for or while loops as seen in imperative languages.

By fundamental constructs I meant for functional languages specifically. From what I've seen of Haskell, mercury and OCaml (the functional aspect of OCaml anyway), their basic constructs are all more or less the same. When using Lisp functionally, to me anyway, it's constructs seem pretty similar too. Maybe I'm wrong, but then, thats why I posted this.

Basically, I'm wondering what are the least amount of constructs a functional language needs for it to be complete. Or at least, whats the least amount of construct any language needs, regardless of paradigm, but I wanted to deal with functional languages first.
By complete, I don't mean turing complete, but rather what a language needs for it to be considered useful.


I find it funny that I actually did learn something from this thread and, in fact, from /prog/ in general. And the trolls just keep it entertaining.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List