tuple space

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

tuple space

Mike Houghton
Hi,

I’m thinking about how to write  a Tuple Space (TS)  in Haskell.

A tuple can  have many fields of different types, in pseudo code something like

T = (1, ”A string”,  3.4)    i.e. an int, string and double.

How can this (and the many variations) be done in Haskell?

(In Java it would be a list of Object)



Thanks

Mike


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: tuple space

Imants Cekusins
> T = (1, ”A string”,  3.4)    i.e. an int, string and double.

would this suit:

data Object = Int' Int | Double' Double | String' String
type T = [Object]

?
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: tuple space

Mike Houghton
Thanks for the quick reply!

No, that wouldn’t work as that would tie a tuple to Int, Double,String for all tuples.

(1,1,2,3,”string”, 4.5, “string”, 1) is also valid tuple

In Java  I would use
List<Object> so any number of (non-primitives) can be used.

Thanks

Mike


> On 5 Feb 2016, at 21:43, Imants Cekusins <[hidden email]> wrote:
>
>> T = (1, ”A string”,  3.4)    i.e. an int, string and double.
>
> would this suit:
>
> data Object = Int' Int | Double' Double | String' String
> type T = [Object]
>
> ?
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: tuple space

Tony Morris
HList.

Also in Java, you'd use HList (never use Object).
http://www.functionaljava.org/javadoc/4.0/fj/data/hlist/HList.html

On Sat, Feb 6, 2016 at 7:58 AM, Mike Houghton <[hidden email]> wrote:
Thanks for the quick reply!

No, that wouldn’t work as that would tie a tuple to Int, Double,String for all tuples.

(1,1,2,3,”string”, 4.5, “string”, 1) is also valid tuple

In Java  I would use
List<Object> so any number of (non-primitives) can be used.

Thanks

Mike


> On 5 Feb 2016, at 21:43, Imants Cekusins <[hidden email]> wrote:
>
>> T = (1, ”A string”,  3.4)    i.e. an int, string and double.
>
> would this suit:
>
> data Object = Int' Int | Double' Double | String' String
> type T = [Object]
>
> ?
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: tuple space

Imants Cekusins
In reply to this post by Mike Houghton
> (1,1,2,3,”string”, 4.5, “string”, 1) is also valid tuple

[Int' 1, Int' 1, Int' 2, Int' 3, String' "string", Double' 4.5,
String' "string", Int 1]

not sure about Double but the rest should be ok. try it!
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: tuple space

Mike Houghton
In reply to this post by Tony Morris
Nice, thanks.

On 5 Feb 2016, at 22:03, Tony Morris <[hidden email]> wrote:

HList.

Also in Java, you'd use HList (never use Object).
http://www.functionaljava.org/javadoc/4.0/fj/data/hlist/HList.html

On Sat, Feb 6, 2016 at 7:58 AM, Mike Houghton <[hidden email]> wrote:
Thanks for the quick reply!

No, that wouldn’t work as that would tie a tuple to Int, Double,String for all tuples.

(1,1,2,3,”string”, 4.5, “string”, 1) is also valid tuple

In Java  I would use
List<Object> so any number of (non-primitives) can be used.

Thanks

Mike


> On 5 Feb 2016, at 21:43, Imants Cekusins <[hidden email]> wrote:
>
>> T = (1, ”A string”,  3.4)    i.e. an int, string and double.
>
> would this suit:
>
> data Object = Int' Int | Double' Double | String' String
> type T = [Object]
>
> ?
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners


_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: tuple space

Imants Cekusins
In reply to this post by Tony Morris
> in Java, you'd use HList (never use Object).

this is new to me. How is it different from List?
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
Reply | Threaded
Open this post in threaded view
|

Re: tuple space

Mike Houghton
In Java
List<T> ensures all entries are of type T  - so only one type allowed.
List<Object> allows anything but you lose type safety.

HList allows anything and retains the types. (but you do get a lot of <<< >>>>>> in declarations :) and really its pushing Java into something it isn’t. )


> On 5 Feb 2016, at 22:13, Imants Cekusins <[hidden email]> wrote:
>
>> in Java, you'd use HList (never use Object).
>
> this is new to me. How is it different from List?
> _______________________________________________
> Beginners mailing list
> [hidden email]
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners

_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners