What extension do I need to write "type Job = Map k a"?

Hi, I've forgotten this. This is OK: type Job k a = Map k a And this is OK: {-# LANGUAGE RankNTypes #-} -- or LiberalTypeSynonyms? type Job = forall a. forall k. Map k a Then how to write it like this? type Job = Map k a -- 竹密岂妨流水过 山高哪阻野云飞 And for G+, please use magiclouds#gmail.com.

On 13 June 2012 19:59, Magicloud Magiclouds
Hi, I've forgotten this. This is OK: type Job k a = Map k a And this is OK: {-# LANGUAGE RankNTypes #-} -- or LiberalTypeSynonyms? type Job = forall a. forall k. Map k a
Then how to write it like this? type Job = Map k a
Does that even make sense? What are the types of `k' and `a' in Job? -- Ivan Lazar Miljenovic Ivan.Miljenovic@gmail.com http://IvanMiljenovic.wordpress.com

Do you want to hide the specific types of the job? Presumably to then
define a type JobList = [Job] ?
You can do that with the ExistentialQuantification extension.
type Job = forall k a. Map k a
type JobList = [Job]
??
Note you can't unpack the types k a once you have hidden them. But the
typechecker can use it to ensure some static property.
Also you could use unsafeCoerce to do some casts, but *only if you are
*sure* that things will go OK*.
2012/6/13 Magicloud Magiclouds
Hi, I've forgotten this. This is OK: type Job k a = Map k a And this is OK: {-# LANGUAGE RankNTypes #-} -- or LiberalTypeSynonyms? type Job = forall a. forall k. Map k a
Then how to write it like this? type Job = Map k a -- 竹密岂妨流水过 山高哪阻野云飞
And for G+, please use magiclouds#gmail.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ismael

That doesn't require existential quantification, but it'll need Rank-2
types if you ever do anything with Job. Unfortunately, a universally
quantified Job like what you wrote (or what Magicloud seems to want) is
only inhabited by the empty Map.
An existentially quantified Job, as you might get with
data Job = forall k a. Job (Map k a)
does let you wrap up any Map containing anything in it, but unfortunately
the only thing you can do with that map afterwards is ask for "structural"
properties about it, like whether it's empty or how many elements it has in
it. You could ask to enumerate the elements in it, but you wouldn't be able
to touch any of them because you wouldn't know what their types were.
So I'm not really sure how to interpret the question. Was the goal to have
a heterogeneous Map, maybe? Or just to avoid having to type type variables
all over the place? Both of those are possible but require a bit more
sophistication with types.
-Dan
On Wed, Jun 13, 2012 at 7:32 AM, Ismael Figueroa Palet wrote: Do you want to hide the specific types of the job? Presumably to then
define a type JobList = [Job] ?
You can do that with the ExistentialQuantification extension. type Job = forall k a. Map k a
type JobList = [Job] ??
Note you can't unpack the types k a once you have hidden them. But the
typechecker can use it to ensure some static property.
Also you could use unsafeCoerce to do some casts, but *only if you are
*sure* that things will go OK*. 2012/6/13 Magicloud Magiclouds Hi,
I've forgotten this.
This is OK:
type Job k a = Map k a
And this is OK:
{-# LANGUAGE RankNTypes #-} -- or LiberalTypeSynonyms?
type Job = forall a. forall k. Map k a Then how to write it like this?
type Job = Map k a
--
竹密岂妨流水过
山高哪阻野云飞 And for G+, please use magiclouds#gmail.com. _______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe --
Ismael _______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Hi there,
Thanks for the reply. To be clear, all I want is to "avoid having to
type type variables all over the place". What should I do? My original
code with RankNTypes and ImpredicativeTypes does not work....
The "type Job = forall k a. M.Map k a" works now. But function uses
it does not. Compiler complains about "Couldn't match expected type
`Job' with actual type `M.Map k0 b0'".
On Wed, Jun 13, 2012 at 9:15 PM, Daniel Peebles
That doesn't require existential quantification, but it'll need Rank-2 types if you ever do anything with Job. Unfortunately, a universally quantified Job like what you wrote (or what Magicloud seems to want) is only inhabited by the empty Map.
An existentially quantified Job, as you might get with
data Job = forall k a. Job (Map k a)
does let you wrap up any Map containing anything in it, but unfortunately the only thing you can do with that map afterwards is ask for "structural" properties about it, like whether it's empty or how many elements it has in it. You could ask to enumerate the elements in it, but you wouldn't be able to touch any of them because you wouldn't know what their types were.
So I'm not really sure how to interpret the question. Was the goal to have a heterogeneous Map, maybe? Or just to avoid having to type type variables all over the place? Both of those are possible but require a bit more sophistication with types.
-Dan
On Wed, Jun 13, 2012 at 7:32 AM, Ismael Figueroa Palet
wrote: Do you want to hide the specific types of the job? Presumably to then define a type JobList = [Job] ? You can do that with the ExistentialQuantification extension.
type Job = forall k a. Map k a type JobList = [Job]
?? Note you can't unpack the types k a once you have hidden them. But the typechecker can use it to ensure some static property. Also you could use unsafeCoerce to do some casts, but *only if you are *sure* that things will go OK*.
2012/6/13 Magicloud Magiclouds
Hi, I've forgotten this. This is OK: type Job k a = Map k a And this is OK: {-# LANGUAGE RankNTypes #-} -- or LiberalTypeSynonyms? type Job = forall a. forall k. Map k a
Then how to write it like this? type Job = Map k a -- 竹密岂妨流水过 山高哪阻野云飞
And for G+, please use magiclouds#gmail.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ismael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- 竹密岂妨流水过 山高哪阻野云飞 And for G+, please use magiclouds#gmail.com.

Mmmmh... no, to do that you need ImpredicativeTypes (which is I believe
about to be deprecated).
You have to declare Job a data, not a type, and use
ExistentialQuantification.
2012/6/13 Ismael Figueroa Palet
Do you want to hide the specific types of the job? Presumably to then define a type JobList = [Job] ? You can do that with the ExistentialQuantification extension.
type Job = forall k a. Map k a type JobList = [Job]
?? Note you can't unpack the types k a once you have hidden them. But the typechecker can use it to ensure some static property. Also you could use unsafeCoerce to do some casts, but *only if you are *sure* that things will go OK*.
2012/6/13 Magicloud Magiclouds
Hi, I've forgotten this. This is OK: type Job k a = Map k a And this is OK: {-# LANGUAGE RankNTypes #-} -- or LiberalTypeSynonyms? type Job = forall a. forall k. Map k a
Then how to write it like this? type Job = Map k a -- 竹密岂妨流水过 山高哪阻野云飞
And for G+, please use magiclouds#gmail.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ismael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe

Thank you all. I just want to wrap some complex types.
So I learn from all info above, I still have to use forall explicitly....
On Wed, Jun 13, 2012 at 9:19 PM, Yves Parès
Mmmmh... no, to do that you need ImpredicativeTypes (which is I believe about to be deprecated). You have to declare Job a data, not a type, and use ExistentialQuantification.
2012/6/13 Ismael Figueroa Palet
Do you want to hide the specific types of the job? Presumably to then define a type JobList = [Job] ? You can do that with the ExistentialQuantification extension.
type Job = forall k a. Map k a type JobList = [Job]
?? Note you can't unpack the types k a once you have hidden them. But the typechecker can use it to ensure some static property. Also you could use unsafeCoerce to do some casts, but *only if you are *sure* that things will go OK*.
2012/6/13 Magicloud Magiclouds
Hi, I've forgotten this. This is OK: type Job k a = Map k a And this is OK: {-# LANGUAGE RankNTypes #-} -- or LiberalTypeSynonyms? type Job = forall a. forall k. Map k a
Then how to write it like this? type Job = Map k a -- 竹密岂妨流水过 山高哪阻野云飞
And for G+, please use magiclouds#gmail.com.
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- Ismael
_______________________________________________ Haskell-Cafe mailing list Haskell-Cafe@haskell.org http://www.haskell.org/mailman/listinfo/haskell-cafe
-- 竹密岂妨流水过 山高哪阻野云飞 And for G+, please use magiclouds#gmail.com.
participants (5)
-
Daniel Peebles
-
Ismael Figueroa Palet
-
Ivan Lazar Miljenovic
-
Magicloud Magiclouds
-
Yves Parès