Send Beginners mailing list submissions to
[email protected]
To subscribe or unsubscribe via the World Wide Web, visit
http://www.haskell.org/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. A simple remove function (bahad?r altan)
2. Re: A simple remove function (Benjamin Edwards)
3. Re: A simple remove function (Tobias)
4. Re: A simple remove function (AbdulSattar Mohammed)
5. A question about import (bahad?r altan)
6. Re: A question about import (Adrien Haxaire)
7. Re: A question about import (Brent Yorgey)
8. Re: A question about import (Andreas Baldeau)
9. Adding to a package (AbdulSattar Mohammed)
----------------------------------------------------------------------
Message: 1
Date: Sun, 19 Feb 2012 18:00:45 +0000 (GMT)
From: bahad?r altan <[email protected]>
Subject: [Haskell-beginners] A simple remove function
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hello. I'm trying to write a code which deletes the wanted element in a list.
Like this : ?myremove "doaltan" 3 = "doltan". I wrote the code below but it
doesn't even compile. Could you help me with fixing the code? Thanks!
myremove x s = (take ?(s-1) x):(drop (s+1) x)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120219/956d3dd9/attachment-0001.htm>
------------------------------
Message: 2
Date: Sun, 19 Feb 2012 18:28:14 +0000
From: Benjamin Edwards <[email protected]>
Subject: Re: [Haskell-beginners] A simple remove function
To: bahad?r altan <[email protected]>
Cc: "[email protected]" <[email protected]>
Message-ID:
<can6k4niiaznu2gozrr0p6hwxitwytme_fcet+bxzi_nr_uh...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
Look at the types of (:), take, and drop. You want to concat lists,
not append an element to the head of a list. I would recommend looking
at the concat operator (++). Haskell is all about the types! take
returns a list, as does drop. So you need some function of type [a] ->
[a] -> [a], not a -> [a] -> [a].
------------------------------
Message: 3
Date: Sun, 19 Feb 2012 19:27:08 +0100
From: Tobias <[email protected]>
Subject: Re: [Haskell-beginners] A simple remove function
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="iso-8859-1"; Format="flowed"
Am 19.02.2012 19:00, schrieb bahad?r altan:
> myremove x s = (take (s-1) x):(drop (s+1) x)
take :: Int -> [a] -> [a]
drop:: Int -> [a] -> [a]
Both functions return a list, therefore you need the "++" operator to
append two lists:
(++): [a] -> [a] -> [a]
So this is what you get:
(I changed s and x becausee I associate s with a string and x with a number)
myremove :: String -> Int -> String
myremove s x = (take (x-1) s) ++ (drop (x) s)
Notice that you have to drop x elements (and not x+1).
<http://hackage.haskell.org/packages/archive/base/latest/doc/html/Prelude.html#v:take>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120219/5e46bed0/attachment-0001.htm>
------------------------------
Message: 4
Date: Sun, 19 Feb 2012 23:55:02 +0530
From: AbdulSattar Mohammed <[email protected]>
Subject: Re: [Haskell-beginners] A simple remove function
To: bahad?r altan <[email protected]>, [email protected]
Message-ID:
<ca+mxqh_e1xgm-8holznvx9unmtuvulh9i3_fk52nal5pvdj...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
It won't compile because the type of (:) is (:) :: a -> [a] -> [a]. It
takes an element on its left side. take returns a list (take :: Int ->
[a] -> [a]).
Instead of using the (:) operator, use the (++) operator. It appends a
list to another.
So, your function should be: myremove x s = (take (s-1) x) ++ (drop (s+1) x)
But it won't do what you're expecting it to do because, drop 3
"doaltan" would remove doa" and give you "lo". It removes the first 3
elements. So, your drop (s+1) would remove (3+1), elements, i.e,
"doal". Change it to drop s.
So, your final function should be:
myremove x s = (take (s-1) x) ++ (drop s x)
And by the way, welcome to Haskell!
On Sun, Feb 19, 2012 at 11:30 PM, bahad?r altan <[email protected]> wrote:
> Hello. I'm trying to write a code which deletes the wanted element in a
> list. Like this : ?myremove "doaltan" 3 = "doltan". I wrote the code below
> but it doesn't even compile. Could you help me with fixing the code? Thanks!
>
> myremove x s = (take ?(s-1) x):(drop (s+1) x)
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
--
Warm Regards,
AbdulSattar Mohammed
------------------------------
Message: 5
Date: Sun, 19 Feb 2012 19:50:33 +0000 (GMT)
From: bahad?r altan <[email protected]>
Subject: [Haskell-beginners] A question about import
To: "[email protected]" <[email protected]>
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi, when I try to use import like these:
import System.Random
import Control.Monad?
I get this error: "Syntax error in input (unexpected keyword "import")". Can
you tell me why this happens and how I can fix it?
Thanks..
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://www.haskell.org/pipermail/beginners/attachments/20120219/caa27a20/attachment-0001.htm>
------------------------------
Message: 6
Date: Sun, 19 Feb 2012 21:56:27 +0100
From: Adrien Haxaire <[email protected]>
Subject: Re: [Haskell-beginners] A question about import
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=ISO-8859-1
Hi,
It is difficult to see why here without the context. Could you paste
your code on hpaste.org?
Adrien
On 19/02/2012 20:50, bahad?r altan wrote:
> Hi, when I try to use import like these:
> import System.Random
> import Control.Monad
>
> I get this error: "Syntax error in input (unexpected keyword "import")". Can
> you tell me why this happens and how I can fix it?
> Thanks..
>
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 7
Date: Sun, 19 Feb 2012 16:04:58 -0500
From: Brent Yorgey <[email protected]>
Subject: Re: [Haskell-beginners] A question about import
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Perhaps because you put the imports in the middle of your code?
imports must be the very first thing at the top of a module.
-Brent
On Sun, Feb 19, 2012 at 09:56:27PM +0100, Adrien Haxaire wrote:
> Hi,
>
> It is difficult to see why here without the context. Could you paste
> your code on hpaste.org?
>
> Adrien
>
>
>
> On 19/02/2012 20:50, bahad?r altan wrote:
> > Hi, when I try to use import like these:
> > import System.Random
> > import Control.Monad
> >
> > I get this error: "Syntax error in input (unexpected keyword "import")".
> > Can you tell me why this happens and how I can fix it?
> > Thanks..
> >
> >
> >
> > _______________________________________________
> > Beginners mailing list
> > [email protected]
> > http://www.haskell.org/mailman/listinfo/beginners
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
------------------------------
Message: 8
Date: Sun, 19 Feb 2012 22:31:43 +0100
From: Andreas Baldeau <[email protected]>
Subject: Re: [Haskell-beginners] A question about import
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=iso-8859-1
Hi,
it's hard to see without context, but I'd expect you have misplaced the
imports. The imports go between the module header and your first top level
definition.
Hope this helps,
Andreas
On 19:50 Sun 19 Feb , bahad?r altan wrote:
> Hi, when I try to use import like these:
> import System.Random
> import Control.Monad?
>
> I get this error: "Syntax error in input (unexpected keyword "import")". Can
> you tell me why this happens and how I can fix it?
> Thanks..
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
------------------------------
Message: 9
Date: Mon, 20 Feb 2012 13:03:53 +0530
From: AbdulSattar Mohammed <[email protected]>
Subject: [Haskell-beginners] Adding to a package
To: [email protected]
Message-ID:
<CA+mXQh-5iFMCwAdV57vhyC5Kwy7CnRUgp3=sz0znejexqfj...@mail.gmail.com>
Content-Type: text/plain; charset=ISO-8859-1
I just submitted a patch to Wai, but I didn't like the process I went
through while testing it on my machine.
I cloned the repo, modified it and ran
runghc Setup configure --prefix=$HOME --user
runghc Setup install
That registered as something like wai-2.1.1.1. ( I don't know what it
exactly looked like, but it appended a ".1" to the previous version.)
When I ran my test code, it used the latest version. Fine.
But, is this the way everyone does that? I mean, adding a new version?
I can't think of any other way, but I'm just against registering the
package into the GHC registry. How does everyone do that?
--
Warm Regards,
AbdulSattar Mohammed
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 44, Issue 20
*****************************************