Допис з розмови
reads
Path: g2news1.google.com!news2.google.com!news.glorb.com!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail
From: Frank Poettgen <Frank.Poett...@Post.RxWyTxH-AyAzCyHzEyN.de>
Newsgroups: comp.lang.haskell
Subject: Re: reads
Date: Fri, 12 Jun 2009 13:34:26 +0200
Lines: 60
Message-ID: <79espvF1qbiroU1@mid.dfncis.de>
References: <79ci0lF1pj6nuU1@mid.dfncis.de> <87ski6c0bg.fsf@ixod.org> <20090611170551.274F.1.NOFFLE@dthierbach.news.arcor.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.dfncis.de AV0AW+O0CmolnwIEalkkhQ5MEwtbbDZCHYfzfEhJCVTbDA/igWdZxl2g75
Cancel-Lock: sha1:C2BjVEXo7+OCMfouM6ywVm1gMg0=
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
In-Reply-To: <20090611170551.274F.1.NOFFLE@dthierbach.news.arcor.de>
Dirk Thierbach schrieb:
> Mark T.B. Carroll <Mark.Carr...@aetion.com> wrote:
>> Frank Poettgen <Frank.Poett...@Post.RxWyTxH-AyAzCyHzEyN.de> writes:
>>
>>> I would expect
>>>
>>> reads "1.2" :: [(Int,String)]
>>>
>>> to be evaluated to
>>>
>>> [(1,".2")]
>>>
>>> but using Hugs (Version Sep 2006) it is just
>>>
>>> []
>>>
>>> Bug or feature?
>
>> Good question. GHCi, version 6.8.2, agrees with Hugs.
>
> The reason at least in GHC is that all numeric instances use the same
> function to parse the string. The string is then converted, unless
> conversion fails.
Thanks for your explanation.
> Because of that, one also gets e.g.
>> reads "1e2" :: [(Int,String)]
> [(100,"")]
Really? -Hugs says [].
:type 1e2
100.0 :: Fractional a => a
> AFAIK the report doesn't specify exactly how to parse a number, so I
> strongly suspect "feature". But I never noticed that before, too.
It can be a problem doing parsing with polymorphism. Consider '.' to be
a binary infix symbol describing the branching of a tree of arbitrary
type. Then one gets e.g.
parseTree "'a'.'b'.'c'.'d'" :: (Tree Char)
/\
/\d
/\c
ab
parseTree "1.2.3.4" :: (Tree Float)
/\
/ \
1.2 3.4
but
parseTree "1.2.3.4" :: (Tree Int)
no parse
You can't parse a tree of type String as well (without escape codes),
but that's obvious.