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. "type" declarations: utterly transparent synonyms? (Silent Leaf)
2. Re: "type" declarations: utterly transparent synonyms?
(Imants Cekusins)
3. Re: "type" declarations: utterly transparent synonyms?
(Daniel Bergey)
4. Re: "type" declarations: utterly transparent synonyms?
(Silent Leaf)
5. help on writing a typeclass (Silent Leaf)
6. Re: help on writing a typeclass (Silent Leaf)
----------------------------------------------------------------------
Message: 1
Date: Fri, 3 Jun 2016 18:44:50 +0200
From: Silent Leaf <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] "type" declarations: utterly transparent
synonyms?
Message-ID:
<cagfccjnyaw8e2tawpx9sfgxoejcnyxbb8mfwp8qdicwyyyk...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I'd like to be sure when one defines a type with "type", it truly merely
creates a synonym, and no matter what one could replace the left side by
the right side in the whole program, and vice versa, and it wouldn't change
a thing in the actual meaning, value of the program.
Eg if i define:
type In2 t = t -> t -> t
I can thereafter replace for any type t, any signature like
f :: t -> t -> t
with
f :: In2 t
then strictly no consequence other than visual in the source code, by me,
will occur.
Thanks!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160603/b34b4bec/attachment-0001.html>
------------------------------
Message: 2
Date: Fri, 3 Jun 2016 18:54:17 +0200
From: Imants Cekusins <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] "type" declarations: utterly
transparent synonyms?
Message-ID:
<CAP1qinZjr-ANSKUfTXA6_ct=LFLEYpbc5dxnLBxXJ-caYh9x=g...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
it seems so.. different synonyms with similar "content" are substituted /
matched without errors:
data D = S String | I Int deriving (Eq,Ord)
type A = D
type B = D
compiler "won't mind" if
Set A
is replaced with
Set B
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160603/ff3f9e86/attachment-0001.html>
------------------------------
Message: 3
Date: Fri, 03 Jun 2016 14:01:00 -0400
From: Daniel Bergey <[email protected]>
To: Silent Leaf <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] "type" declarations: utterly
transparent synonyms?
Message-ID:
<87poryw3s3.fsf@chladni.i-did-not-set--mail-host-address--so-tickle-me>
Content-Type: text/plain
Yes, it is as you say. The Haddock documentation will use the type
synonym if (and only if) you use it in the type of f. Call sites of f,
and the result of f, are the same regardless.
For example, this is fine:
f :: t -> t -> t
g :: Int2 t
g = f
cheers,
bergey
On 2016-06-03 at 12:44, Silent Leaf <[email protected]> wrote:
> I'd like to be sure when one defines a type with "type", it truly merely
> creates a
> synonym, and no matter what one could replace the left side by the right side
> in the
> whole program, and vice versa, and it wouldn't change a thing in the actual
> meaning,
> value of the program.
>
> Eg if i define:
> type In2 t = t -> t -> t
> I can thereafter replace for any type t, any signature like
> f :: t -> t -> t
> with
> f :: In2 t
> then strictly no consequence other than visual in the source code, by me,
> will occur.
> Thanks!
>
> _______________________________________________
> Beginners mailing list
> [email protected]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
Message: 4
Date: Sat, 4 Jun 2016 00:28:46 +0200
From: Silent Leaf <[email protected]>
To: Daniel Bergey <[email protected]>, The Haskell-Beginners
Mailing List - Discussion of primarily beginner-level topics related
to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] "type" declarations: utterly
transparent synonyms?
Message-ID:
<CAGFccjMT_hqc-=zxlcwfvud0cdby7z0ad20uj3vzf7inpdj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Thanks!
Le vendredi 3 juin 2016, Daniel Bergey <[email protected]> a ?crit :
> Yes, it is as you say. The Haddock documentation will use the type
> synonym if (and only if) you use it in the type of f. Call sites of f,
> and the result of f, are the same regardless.
>
> For example, this is fine:
>
> f :: t -> t -> t
>
> g :: Int2 t
> g = f
>
> cheers,
> bergey
>
> On 2016-06-03 at 12:44, Silent Leaf <[email protected]> wrote:
>> I'd like to be sure when one defines a type with "type", it truly merely
creates a
>> synonym, and no matter what one could replace the left side by the right
side in the
>> whole program, and vice versa, and it wouldn't change a thing in the
actual meaning,
>> value of the program.
>>
>> Eg if i define:
>> type In2 t = t -> t -> t
>> I can thereafter replace for any type t, any signature like
>> f :: t -> t -> t
>> with
>> f :: In2 t
>> then strictly no consequence other than visual in the source code, by
me, will occur.
>> Thanks!
>>
>> _______________________________________________
>> 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/20160604/d8dcdd7e/attachment-0001.html>
------------------------------
Message: 5
Date: Sat, 4 Jun 2016 01:28:37 +0200
From: Silent Leaf <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: [Haskell-beginners] help on writing a typeclass
Message-ID:
<CAGFccjNKuFtzQwSi9ywvQVBJfJdFZOqaPFUdi=sU0c=verj...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
I got a function, named mdk (don't ask). It happens it's a method of a
class, as follows:
class C a where
mdk :: C b => a -> b -> (a, b)
yet i got another function, called so far mdk'
mdk' :: C b => b -> a -> (a, b)
Say there are the following instances:
instance C X where
mdk x b = ... :: C b => (X, b)
mdk' b x = ... :: C b => (X, b)
instance C Y where
mdk y b = ... :: C b => (Y, b)
mdk' b y = ... :: C b => (Y, b)
if you get what's happening, mdk and mdk' are basically the same method,
save for the final type-result, which is reversed, without data loss mind
you (aka (A, B) and (B, A) could be the same type, if only i knew of a way
to make a type in haskell without forcing the order (a kind of set or
something).
so, there are four cases:
input have types, in this order, X and Y, and expected output is (X, Y):
then mdk from X's instance of C is called/must be used;
input have types Y and X, output (X, Y): X's mdk'
input X and Y, output (Y, X): Y's mdk
input Y and X, output (Y, X): Y's mdk'
it might seem confusing, but all amounts to the issue that even though (Y,
X) is strictly equivalent, in my program, to (X, Y), in principle haskell
differentiate the types.
thus i have to write two versions of mdk for each type, even though the
methods "X's mdk" and "Y's mdk'" are identical, and same for the two other
methods.
indeed:
mdk :: C b => X -> b -> (X, b)
mdk' :: C b => b -> Y -> (Y, b)
are identical signatures, if in the first one you replace `b` with Y, and
in the latter you replace `b` with X, and ofc if you consider (X,Y) ==
(Y,X).
only one of those two methods should be enough to handle the job, and be
chosen by the compiler on the sole value of the type of the first variable;
but the fact both methods return tuples of "mirrored" types, crushes that.
if i only write `mdk` instances, as soon as the compiler will meet this
following signature:
mdk :: a -> b -> (b, a)
it will crash an exception, because mdk's original signature has for output
value a tuple whose first type should here be `a`, because it's meant to be
the type of the first argument, not the second.
thus, at last my question: can i tell the compiler to consider (b, a) and
(a, b) as identical types (don't worry it's not really a tuple in my
program, but it's equivalent)?
if not, can i make an overloading of mdk so it accepts both a->b->(a,b) and
a->b->(b,a)?
hope i didn't lose anyone. if so, do tell me, i'll try to clarify.
thanks in advance of the time spent trying to understand my problem!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160604/3acedcbb/attachment-0001.html>
------------------------------
Message: 6
Date: Sat, 4 Jun 2016 01:57:54 +0200
From: Silent Leaf <[email protected]>
To: The Haskell-Beginners Mailing List - Discussion of primarily
beginner-level topics related to Haskell <[email protected]>
Subject: Re: [Haskell-beginners] help on writing a typeclass
Message-ID:
<CAGFccjO5kKybwGVs13xQT1cy_UgMT=4mqjm0rigrwz177n5...@mail.gmail.com>
Content-Type: text/plain; charset="utf-8"
Got an idea, is it the right path? Are there bad consequences in using the
extensions that are necessaries to make the code work?
class Mdk binary a | binary -> a where
mdk :: a -> b -> binary
instance Mdk (a,b) a where
mdk = ... :: a -> b -> (a,b)
instance Mdk (b, a) a where
mdk = ... :: a -> b -> (b, a)
then, however, even if it works, mdk will never be part of the other class
i was working on, and at that point i'm a bit lost on the consequences of
this...
Le samedi 4 juin 2016, Silent Leaf <[email protected]> a ?crit :
> I got a function, named mdk (don't ask). It happens it's a method of a
class, as follows:
>
> class C a where
> mdk :: C b => a -> b -> (a, b)
>
> yet i got another function, called so far mdk'
> mdk' :: C b => b -> a -> (a, b)
>
>
> Say there are the following instances:
> instance C X where
> mdk x b = ... :: C b => (X, b)
> mdk' b x = ... :: C b => (X, b)
> instance C Y where
> mdk y b = ... :: C b => (Y, b)
> mdk' b y = ... :: C b => (Y, b)
>
> if you get what's happening, mdk and mdk' are basically the same method,
save for the final type-result, which is reversed, without data loss mind
you (aka (A, B) and (B, A) could be the same type, if only i knew of a way
to make a type in haskell without forcing the order (a kind of set or
something).
> so, there are four cases:
> input have types, in this order, X and Y, and expected output is (X, Y):
then mdk from X's instance of C is called/must be used;
> input have types Y and X, output (X, Y): X's mdk'
> input X and Y, output (Y, X): Y's mdk
> input Y and X, output (Y, X): Y's mdk'
>
> it might seem confusing, but all amounts to the issue that even though
(Y, X) is strictly equivalent, in my program, to (X, Y), in principle
haskell differentiate the types.
> thus i have to write two versions of mdk for each type, even though the
methods "X's mdk" and "Y's mdk'" are identical, and same for the two other
methods.
> indeed:
> mdk :: C b => X -> b -> (X, b)
> mdk' :: C b => b -> Y -> (Y, b)
> are identical signatures, if in the first one you replace `b` with Y, and
in the latter you replace `b` with X, and ofc if you consider (X,Y) ==
(Y,X).
>
> only one of those two methods should be enough to handle the job, and be
chosen by the compiler on the sole value of the type of the first variable;
but the fact both methods return tuples of "mirrored" types, crushes that.
if i only write `mdk` instances, as soon as the compiler will meet this
following signature:
> mdk :: a -> b -> (b, a)
> it will crash an exception, because mdk's original signature has for
output value a tuple whose first type should here be `a`, because it's
meant to be the type of the first argument, not the second.
>
> thus, at last my question: can i tell the compiler to consider (b, a) and
(a, b) as identical types (don't worry it's not really a tuple in my
program, but it's equivalent)?
> if not, can i make an overloading of mdk so it accepts both a->b->(a,b)
and a->b->(b,a)?
>
> hope i didn't lose anyone. if so, do tell me, i'll try to clarify.
>
> thanks in advance of the time spent trying to understand my problem!
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
<http://mail.haskell.org/pipermail/beginners/attachments/20160604/76a7c73f/attachment.html>
------------------------------
Subject: Digest Footer
_______________________________________________
Beginners mailing list
[email protected]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
------------------------------
End of Beginners Digest, Vol 96, Issue 6
****************************************