[1] Bug1?
This declaration:
> A = (,) Int Int
is accepted by ghci. Is this behaveour correct,
1. It kind of shadows (,) is defined in PrelTup meaning that you can no longer
use (,) prefix to refer to tuples - like (,) 1 2.
2. Seems to me like (,) is not correct syntax for a consym as defined in the
H98 Report so we shouldn't be able to redefine it.
Note: didn't check any other interpreter/compiler.
[2] Bug2?
- Step 1
Load this in ghci,
-----------------------
module Test where
data C = C ((,) Int Int)
data A = (,) !Int !Int
h :: A
h = (,) 1 2
{-
f :: C
f = C ((,) 3 4)
-}
------------------------
- Step 2
Uncomment the f function. (you'll get an error function)
- Step 3
To get rid of the error comment out the 'data A' declaration and function 'h'.
Now you should get this error message:
-------------------------------------------------
Failed to find interface decl for `Teste.A'
from module `Teste'
-------------------------------------------------
[3] Strict Pairs question
I really miss them :-)
I know I can do something like
data A a b= A !a !b
But then you can't use zips fst etc etc...
One possible solution would be to add some Class Pair, with default instances
for these functions. Is this a bad idea for any particular reason?
It would also be nice to be able to generalize the idea syntatic sugar for
standar tuples and be able to define constructors like, say
(:,:) and (#:, , :#) etc. Is this feasable?
J.A.
On Wednesday 17 April 2002 03:15, Jorge Adriano wrote:
[1] Bug1? This declaration:
A = (,) Int Int
Opsss cut and paste problems :)
data A = (,) Int Int is accepted by ghci. Is this behaveour correct,
This is what I meant. Anyway in Bug 2 I used the 'correct' declaration
[2] Bug2? - Step 1 Load this in ghci, ----------------------- module Test where data C = C ((,) Int Int)
data A = (,) !Int !Int -- <----------- There it is <snip>
J.A.
On Tuesday 16 April 2002 07:15 pm, Jorge Adriano wrote:
[1] Bug1?
This declaration:
A = (,) Int Int
is accepted by ghci. Is this behaveour correct, 1. It kind of shadows (,) is defined in PrelTup meaning that you can no longer use (,) prefix to refer to tuples - like (,) 1 2. 2. Seems to me like (,) is not correct syntax for a consym as defined in the H98 Report so we shouldn't be able to redefine it. ...
I found that ghci (I'm using version 5.02.2) will also allow you to reuse [] as a constructor, as in:
data Foo a = [] a deriving Show
For some reason, though, this has the side effect of causing a segmentation fault whenever I type in a literal list like [1,2,3]. Here are some other weird things you can try:
data [] a = [] Int deriving Show --ghci complains about duplicate instances
data [] = [] Int deriving Show
Test> [] 6543 [] 6543 Test> :i [] -- PrelBase.[] is a data constructor PrelBase.[] :: Int*** Exception: Prelude.head: empty list
data (,) a b = (,) b a
Test> ('a',72::Int) ('a',72) Test> (,) 'a' (72::Int) (97,'H')
data (,) a b = (,) b a typecast :: a -> b typecast x = fst ((,) x undefined)
Evidently, when you redefine the datatypes [] or (,), you can change the internal representation of those types, without affecting their class instances or other functions that may have depended on the original representation. Obviously this does not preserve type safety. I see two possible remedies: (1) Simply disallow [] and (,) as user-defined types, or (2) Allow users to define their own versions of [] and (,), but use qualified names to distinguish them from the originals. - Brian Huffman
participants (2)
-
Brian Huffman -
Jorge Adriano