Embedding newlines into a string? [Was: Re: [Haskell-cafe] Separate a string into a list of strings]

2008-04-14 Thread Benjamin L. Russell
A friend and I were working on a Haskell version of Towers of Hanoi yesterday, and I tried writing out the program today, but got stuck on outputting newlines as part of the string; viz: hanoi :: Int - String hanoi n = hanoi_helper 'a' 'b' 'c' n hanoi_helper :: Char - Char - Char - Int

Re: Embedding newlines into a string? [Was: Re: [Haskell-cafe] Separate a string into a list of strings]

2008-04-14 Thread Neil Mitchell
Hi On Mon, Apr 14, 2008 at 8:22 AM, Benjamin L. Russell [EMAIL PROTECTED] wrote: A friend and I were working on a Haskell version of Towers of Hanoi yesterday, and I tried writing out the program today, but got stuck on outputting newlines as part of the string; viz: | n == 1 =

[Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Sara Kenedy
Hi all, I want to write a function to separate a string into a list of strings separated by commas. Example: separate :: String - [String] separate Haskell, Haskell, and Haskell = [Haskell, Haskell, and Haskell] If anyone has some ideas, please share with me. Thanks. S.

Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread J. Garrett Morris
Off the top of my head: separate :: String - [String] separate [] = [] separate s = case break (',' ==) s of (s,[]) - [s] (s,',':s') - s : separate s' _ - error how did we get here? There is at least one cunning rewriting with foldl, I think, but I think this version is clearer. /g

Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Neil Mitchell
Hi, I tend to use the module TextUtil (or Util.Text) from Yhc for these kind of string manipulations: http://www-users.cs.york.ac.uk/~malcolm/cgi-bin/darcsweb.cgi?r=yhc;a=headblob;f=/src/compiler98/Util/Text.hs separate = splitList , I am currently thinking about making this module into a

Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Clifford Beshers
Sara Kenedy wrote: Hi all, I want to write a function to separate a string into a list of strings separated by commas. Example: separate :: String - [String] separate "Haskell, Haskell, and Haskell" = ["Haskell", "Haskell", "and Haskell"] If anyone has some ideas,

Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Brandon Moore
Clifford Beshers wrote: Sara Kenedy wrote: Hi all, I want to write a function to separate a string into a list of strings separated by commas. Example: separate :: String - [String] separate Haskell, Haskell, and Haskell = [Haskell, Haskell, and Haskell] If anyone has some ideas, please

Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Jared Updike
Funny. I have a module called Useful.hs with some of these same sorts of functions. (coming from Python where I used .split(',') and .replace('\r', '') and such a lot): -- module Useful where import List ( intersperse, tails ) import Numeric ( readHex ) hex2num :: (Num a) =

Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Neil Mitchell
Hi beginsWith [] [] = True beginsWith _[] = True beginsWith [] _ = False beginsWith (a:aa) (b:bb) | a == b = aa `beginsWith` bb | otherwise= False I used to have this in my library then I discovered isPrefixOf :) (or flip

Re: [Haskell-cafe] Separate a string into a list of strings

2006-06-12 Thread Clifford Beshers
Brandon Moore wrote: Going by man grep, those [:foo:] classes are only special inside a character class, otherwise [:space:]* = [aceps:]*. Prelude Text.Regex splitRegex (mkRegex [[:space:]]*,[[:space:]]*) Haskell, Haskell, and Haskell [Haskell,Haskell,and Haskell] The smart money was