pattern matching on strings ?

Hello, Im try to the solve the exercise which does the following : "E 2 562 help he and convert it into (Error 2) 562 "help help First I thought to split the string on the " " but according to google Haskell do not have a split function. Can I use pattern matching on some way ? Roelof

On Fri, Feb 20, 2015 at 1:32 AM, Roelof Wobben
Hello,
Im try to the solve the exercise which does the following :
"E 2 562 help he
and convert it into
(Error 2) 562 "help help
First I thought to split the string on the " " but according to google Haskell do not have a split function.
Can I use pattern matching on some way ?
You can do pattern matching on lists, and strings are lists of chars, so you can always do it that way. I'm not sure what you mean by "Haskell do not have a split function". It may not have one by that name, but it has a bunch of functions for splitting up lists and strings. If you want a list of words, then words will give it to you. If you want to split it into two halves, then either span or break will do that for you. Neither discards the dividing character, since they take a predicate to determine the split rather than a value, which means the dividing character may not be obvious after the split. It's common to find that where procedural languages take a value to test against, functional ones take a predicate that does the test, as it's trivial to create a predicate to test for equality with a specific value. You might also want to look through Data.Char for interesting predicates (like isSpace) to use with those functions.

Roelof,
If you are working with a String type, you should remember that its just a
list of chars:
type String = [Char]
So, you can take a look at different split functions at Data.List module.
If your strings are of type Text, look at Data.Text module for split
functions.
Cheers.
20 лют. 2015 08:32, користувач "Roelof Wobben"
Hello,
Im try to the solve the exercise which does the following :
"E 2 562 help he
and convert it into
(Error 2) 562 "help help
First I thought to split the string on the " " but according to google Haskell do not have a split function.
Can I use pattern matching on some way ?
Roelof
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

On 2015-02-20 08:32, Roelof Wobben wrote:
Im try to the solve the exercise which does the following :
"E 2 562 help he
and convert it into
(Error 2) 562 "help help
First I thought to split the string on the " " but according to google Haskell do not have a split function.
Can I use pattern matching on some way ?
Instead of using Google, I suggest to first think about this in terms of types. You're looking for a function which can turn a string into a list of strings, i.e. String -> [String] You can feed types like this to Hoogle ( http://www.haskell.org/hoogle ) to get function which match that type. Searching for the above type signature yields some very relevant hits. :-) -- Frerich Raabe - raabe@froglogic.com www.froglogic.com - Multi-Platform GUI Testing

On Fri, 20 Feb 2015 08:32:17 +0100, Roelof Wobben
First I thought to split the string on the " " but according to google Haskell do not have a split function.
If you use Hoogle[0] instead of Google, you will find that there are many split functions in Haskell libraries. Another Haskell package search engine is Hayoo[1]; Hayoo searches more packages, but Hoogle has the advantage that you can enter the type of a function that you are looking for. Met vriendelijke groet, Henk-Jan van Tuyl [0] https://www.fpcomplete.com/hoogle?q=split [1] http://hayoo.fh-wedel.de/ -- Folding@home What if you could share your unused computer power to help find a cure? In just 5 minutes you can join the world's biggest networked computer and get us closer sooner. Watch the video. http://folding.stanford.edu/ http://Van.Tuyl.eu/ http://members.chello.nl/hjgtuyl/tourdemonad.html Haskell programming --

On Fri, 20 Feb 2015 08:32:17 +0100, Roelof Wobben
wrote: First I thought to split the string on the " " but according to google
Haskell do not have a split function.
As others have already said, Haskell does in fact have a "split on spaces" function (words), and several others flavors of splitting that makes it possible to dissect your list as you wish. If you still want a split function ala Perl, there is a solid "split https://hackage.haskell.org/package/split" package on hackage which propose several standard function and a very configurable generic version of the split concept for all lists. Also, Data.Text comes with several splitting functions for use with the Text datatype. -- Jedaï
participants (6)
-
Chaddaï Fouché
-
Frerich Raabe
-
Henk-Jan van Tuyl
-
Konstantine Rybnikov
-
Mike Meyer
-
Roelof Wobben