Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
or, via email, send a message with subject or body 'help' to
[email protected]
You can reach the person managing the list at
[email protected]
When replying, please edit your Subject line so it is more specific
than "Re: Contents of Beginners digest..."
Today's Topics:
1. pattern matching on strings ? (Roelof Wobben)
2. Re: pattern matching on strings ? (Mike Meyer)
3. Re: pattern matching on strings ? (Konstantine Rybnikov)
4. Re: pattern matching on strings ? (Frerich Raabe)
5. Re: pattern matching on strings ? (Henk-Jan van Tuyl)
----------------------------------------------------------------------
Message: 1
Date: Fri, 20 Feb 2015 08:32:17 +0100
From: Roelof Wobben <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] pattern matching on strings ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=windows-1252; format=flowed
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
------------------------------
Message: 2
Date: Fri, 20 Feb 2015 02:00:48 -0600
From: Mike Meyer <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] pattern matching on strings ?
Message-ID:
<CAD=7u2aq0mngbl5n9ucwe9iykrths8fr5knwcvpcvfgxdhu...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
On Fri, Feb 20, 2015 at 1:32 AM, Roelof Wobben <[email protected]> wrote:
> 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150220/d2b2a1d7/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 20 Feb 2015 10:21:01 +0200
From: Konstantine Rybnikov <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] pattern matching on strings ?
Message-ID:
<CAAbahfQN5AbwywjE=eyebwx4b2oqurhkitahdnfuhuluzcw...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
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" <[email protected]> ???????:
> 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
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20150220/1545826f/attachment-0001.html>
------------------------------
Message: 4
Date: Fri, 20 Feb 2015 09:50:10 +0100
From: Frerich Raabe <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] pattern matching on strings ?
Message-ID: <[email protected]>
Content-Type: text/plain; charset=US-ASCII; format=flowed
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 - [email protected]
www.froglogic.com - Multi-Platform GUI Testing
------------------------------
Message: 5
Date: Fri, 20 Feb 2015 11:53:28 +0100
From: "Henk-Jan van Tuyl" <[email protected]>
To: "The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell" <[email protected]>,
"Roelof Wobben" <[email protected]>
Subject: Re: [Haskell-beginners] pattern matching on strings ?
Message-ID: <op.xucq7j2ppz0j5l@alquantor>
Content-Type: text/plain; charset=iso-8859-15; format=flowed;
delsp=yes
On Fri, 20 Feb 2015 08:32:17 +0100, Roelof Wobben <[email protected]> wrote:
> 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
--
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 80, Issue 57
*****************************************