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. Re: Parse error in pattern (Tom Davie)
2. Re: Parse error in pattern (Daniel Fischer)
3. Small question (edgar klerks)
4. Re: Small question (Alexander Dunlap)
5. Re: Small question (Felipe Lessa)
6. Maximum length of a GHCi command? (Kwanghoon Choi)
7. Re: Maximum length of a GHCi command? (Erlend Hamberg)
8. Re: Maximum length of a GHCi command? (Daniel Fischer)
----------------------------------------------------------------------
Message: 1
Date: Sat, 27 Feb 2010 14:41:29 +0000
From: Tom Davie <[email protected]>
Subject: Re: [Haskell-beginners] Parse error in pattern
To: Daniel Fischer <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
On Fri, Feb 26, 2010 at 5:12 PM, Daniel Fischer <[email protected]>wrote:
> Am Freitag 26 Februar 2010 17:37:30 schrieb Magnus Therning:
> > It doesn't look like a complete piece of code so these comments aren't
> > backed up by running it through GHCi or anything.
> >
> > On Fri, Feb 26, 2010 at 16:29, Florian Duret <[email protected]>
> wrote:
> > > Hello,
> > >
> > >
> > > I try to set up a verification on the number of arguments given to my
> > > program, but keep on getting "Parse error in pattern"
> > > Here is what my code looks like:
> > > main :: IO()
> > > main = do
> > > -- On commence par ouvrir le fichier SAC en mode binaire
> > > argsList <- getArgs
> > > if (length (argsList) == 0)
>
> It's most likely harmless for argument lists (although there are other
> cases), but
>
> Don't Use
>
> if (length list == 0)
>
> Never. Jamais. Niemals.
>
> Use
>
> if (null list)
>
> length has to traverse the entire list, which may take a long time.
While the advice here is sound 90% of the time, it's evidence of falling
into the trap of underestimating lazyness. If 0 and length list are both of
type Nat, the first will be exactly as fast as the second.
Bob
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100227/e3ecf912/attachment-0001.html
------------------------------
Message: 2
Date: Sat, 27 Feb 2010 16:41:17 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Parse error in pattern
To: Tom Davie <[email protected]>
Cc: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Am Samstag 27 Februar 2010 15:41:29 schrieb Tom Davie:
> While the advice here is sound 90% of the time, it's evidence of falling
> into the trap of underestimating lazyness. Â If 0 and length list are
> both of type Nat, the first will be exactly as fast as the second.
>
> Bob
As it is, we have
length :: [a] -> Int
Of course, an implementation with a lazy Int type is thinkable, but for the
time being, it's a pretty safe bet that Int comparisons need complete
evaluation of the arguments. (In GHC, you can use rewrite rules to avoid
it, but if you think of that, you wouldn't write "length xs == k" unless
you really mean it in the first place.)
Most of the uses of "length xs == k" are due to the fact that people are
used to strict list-like structures carrying their length with them and not
to singly linked lazy lists of unknown length, I believe.
So I'd say the advice is sound 100% of the time, though often the lists are
so short that it's not a big deal. Thus the advice may be important less
than 25% of the time.
Now, genericLength is a different case. "genericLength xs == k" is a
dangerous thing if used at strict types, but perfectly fine for lazy
naturals.
P.S.: Tom, I'm curious, why do you sign as Bob?
------------------------------
Message: 3
Date: Sun, 28 Feb 2010 22:06:06 +0100
From: edgar klerks <[email protected]>
Subject: [Haskell-beginners] Small question
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Hi there,
I have created a function mkc:
mkc :: (a -> b) -> a -> m b
mkc f = (\x -> return $ f x)
which works wonderful in statements like:
number <- many1 digit >>= mkc(read)
But somehow I think this function should already exist, it is some kind of
lifting. If it exist where can I find it? Or is there a reason, why it isn't
in prelude, because it is more elegant way to solve this problem.
Thanks in advance,
Edgar
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100228/aa53dbe3/attachment-0001.html
------------------------------
Message: 4
Date: Sun, 28 Feb 2010 13:14:52 -0800
From: Alexander Dunlap <[email protected]>
Subject: Re: [Haskell-beginners] Small question
To: edgar klerks <[email protected]>
Cc: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset=UTF-8
On Sun, Feb 28, 2010 at 1:06 PM, edgar klerks <[email protected]> wrote:
> Hi there,
>
> I have created a function mkc:
>
> mkc :: (a -> b) -> a -> m b
> mkc f = (\x -> return $ f x)
>
> which works wonderful in statements like:
>
> number <- many1 digit >>= mkc(read)
>
> But somehow I think this function should already exist, it is some kind of
> lifting. If it exist where can I find it? Or is there a reason, why it isn't
> in prelude, because it is more elegant way to solve this problem.
>
> Thanks in advance,
>
> Edgar
>
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://www.haskell.org/mailman/listinfo/beginners
>
>
For something like this, we generally do
fmap read (many1 digit)
fmap is equivalent to liftM from Control.Monad and liftA from
Control.Applicative. It has type Functor f => (a -> b) -> (f a -> f
b). All monads can be functors (and all of the standard ones are), so
it can generally be used as a function (a -> b) -> (m a -> m b) for a
monad m. liftM has the type Monad m => (a -> b) -> (m a -> m b).
Alex
Alex
------------------------------
Message: 5
Date: Sun, 28 Feb 2010 18:16:54 -0300
From: Felipe Lessa <[email protected]>
Subject: Re: [Haskell-beginners] Small question
To: [email protected]
Message-ID: <[email protected]>
Content-Type: text/plain; charset=us-ascii
On Sun, Feb 28, 2010 at 10:06:06PM +0100, edgar klerks wrote:
> I have created a function mkc:
>
> mkc :: (a -> b) -> a -> m b
> mkc f = (\x -> return $ f x)
Actually the type is
mkc :: Monad m => (a -> b) -> a -> m b
and you could define it as
mkc = (return .)
However, we usually don't need this function.
> which works wonderful in statements like:
>
> number <- many1 digit >>= mkc(read)
We prefer to right
number <- fmap read (many1 digit)
or, even better yet
import Control.Applicative
number <- read <$> many1 digit
Note that
(<$>) :: Functor f => (a -> b) -> (f a -> f b)
f <$> x = fmap f x
Cheers,
--
Felipe.
------------------------------
Message: 6
Date: Sun, 28 Feb 2010 16:54:38 +0900
From: Kwanghoon Choi <[email protected]>
Subject: [Haskell-beginners] Maximum length of a GHCi command?
To: [email protected]
Message-ID:
<[email protected]>
Content-Type: text/plain; charset="iso-8859-1"
Dear Haskeller,
I have a little issue in using GHCi as follows:
===
Prelude> length
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
<interactive>:1:254:
lexical error in string/character literal at character '\EOT'
===
It seems to me that GHCi doesn't allow me to type more than some specified
length of a command.
Is this interpretation correct? How can I make it longer?
This issue is quite important at least to me. My tool is just a simple
Haskell program. I don't like to add any extra interactive environment, but
I like to just use GHCi as an interactive environment for my tool. I
strongly believe that this ides is pervasive among many haskellers.
Thanks in advance for your help/feedback in advance.
Kwanghoon
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.haskell.org/pipermail/beginners/attachments/20100228/4cf04f4d/attachment-0001.html
------------------------------
Message: 7
Date: Sun, 28 Feb 2010 22:51:47 +0100
From: Erlend Hamberg <[email protected]>
Subject: Re: [Haskell-beginners] Maximum length of a GHCi command?
To: [email protected]
Cc: Kwanghoon Choi <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
On Sunday 28. February 2010 08.54.38 Kwanghoon Choi wrote:
> ===
> Prelude> length
> "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
> aaaaaaaaaaaaaaaaaaaaaaaaaa" <interactive>:1:254:
> lexical error in string/character literal at character '\EOT'
> ===
>
> It seems to me that GHCi doesn't allow me to type more than some specified
> length of a command. Is this interpretation correct? How can I make it
> longer?
Which platform is this? That works perfectly here. Even 1000 characters seems
to work.
If this is on *nix, maybe it has something to do with readline / editline /
whatever is used now?
--
Erlend Hamberg
âEverything will be ok in the end. If its not ok, its not the end.â
GPG/PGP: 0xAD3BCF19
45C3 E2E7 86CA ADB7 8DAD 51E7 3A1A F085 AD3B CF19
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 198 bytes
Desc: This is a digitally signed message part.
Url :
http://www.haskell.org/pipermail/beginners/attachments/20100228/c280120c/attachment-0001.bin
------------------------------
Message: 8
Date: Sun, 28 Feb 2010 23:00:09 +0100
From: Daniel Fischer <[email protected]>
Subject: Re: [Haskell-beginners] Maximum length of a GHCi command?
To: [email protected]
Cc: Kwanghoon Choi <[email protected]>
Message-ID: <[email protected]>
Content-Type: text/plain; charset="utf-8"
Am Sonntag 28 Februar 2010 08:54:38 schrieb Kwanghoon Choi:
> Dear Haskeller,
>
> I have a little issue in using GHCi as follows:
>
> ===
> Prelude> length
> "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
>aaaaaaaaaaaaaaaaaaaaaaaaaaaa" <interactive>:1:254:
> lexical error in string/character literal at character '\EOT'
> ===
Hm,
Prelude> length
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
99
Prelude> length
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
549
And it shouldn't get an \EOT anyway, also column 254 is way past the
String.
>
> It seems to me that GHCi doesn't allow me to type more than some
> specified length of a command.
There's some limit (memory, terminal buffer), but in practice, you
shouldn't ever come near it.
> Is this interpretation correct? How can I make it longer?
>
> This issue is quite important at least to me. My tool is just a simple
> Haskell program. I don't like to add any extra interactive environment,
> but I like to just use GHCi as an interactive environment for my tool. I
> strongly believe that this ides is pervasive among many haskellers.
So, ghci got the command from your tool and not from you typing at the
prompt?
Then it seems your tool outputs unwanted \EOT characters, it might be worth
to check.
>
> Thanks in advance for your help/feedback in advance.
>
> Kwanghoon
------------------------------
_______________________________________________
Beginners mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/beginners
End of Beginners Digest, Vol 20, Issue 39
*****************************************