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
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 =
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.
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
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
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,
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
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) =
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
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
10 matches
Mail list logo