Serialising data between Haskell and C#

Hi All I want to integrate Haskell into an existing C# project, initially by creating one C# class that basically does all it's "work" in Haskell (and just provides a C# interface). There will be a few types passed in and out of this Haskell module from/to C#. On the C# side, there are classes with members, who's types are probably going to be either Strings, Ints, or lists of Strings/Ints, or lists of other objects. I'd like to have the same types on the Haskell side. It would be nice if I could just magically pass one of these C# types to Haskell and on the Haskell side it will appear as a Haskell type I assume what I'll have to do is serialise the type on the C# side and deserialise on the Haskell side. C# allows one to serialise any data type to XML. Haskell has plenty of serialisation libraries as well. However, the problem I presume is that if I just serialise to XML on the C# side, and deserialise from XML on the Haskell side, if my types are just slightly different, or even if the exact serialisers/deserialises represent their data in different ways, it isn't going to work. It seems like passing complex data to/from Haskell may be a common problem other people experience, so I'm looking for any suggestions on a clean way of doing this.

I know this isn't Haskell OR C#, but XSLT comes to mind. That might be a cleaner alternative than affecting either the way Haskell or C# serializes or deserializes. On 3/12/2018 6:06 PM, Clinton Mead wrote:
Hi All
I want to integrate Haskell into an existing C# project, initially by creating one C# class that basically does all it's "work" in Haskell (and just provides a C# interface).
There will be a few types passed in and out of this Haskell module from/to C#. On the C# side, there are classes with members, who's types are probably going to be either Strings, Ints, or lists of Strings/Ints, or lists of other objects.
I'd like to have the same types on the Haskell side.
It would be nice if I could just magically pass one of these C# types to Haskell and on the Haskell side it will appear as a Haskell type
I assume what I'll have to do is serialise the type on the C# side and deserialise on the Haskell side.
C# allows one to serialise any data type to XML. Haskell has plenty of serialisation libraries as well.
However, the problem I presume is that if I just serialise to XML on the C# side, and deserialise from XML on the Haskell side, if my types are just slightly different, or even if the exact serialisers/deserialises represent their data in different ways, it isn't going to work.
It seems like passing complex data to/from Haskell may be a common problem other people experience, so I'm looking for any suggestions on a clean way of doing this.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Haskell has good capabilities for accessing "foreign" data structures (without serialization), and so does C#. A good common denominator is probably COM, because C# can treat COM objects almost like native objects. I see there's a package https://hackage.haskell.org/package/hcom for the Haskell side.

You could use protocol buffers:
https://developers.google.com/protocol-buffers/docs/csharptutorial
You would specify the data types you need in an independent language, then
use a code generator to get C# classes and Haskell records, and serializers
for free. On the Haskell side you can use
https://hackage.haskell.org/package/proto-lens. Then you can send the
serialized objects over FFI or the network as needed.
On Tue, Mar 13, 2018 at 12:06 AM, Clinton Mead
Hi All
I want to integrate Haskell into an existing C# project, initially by creating one C# class that basically does all it's "work" in Haskell (and just provides a C# interface).
There will be a few types passed in and out of this Haskell module from/to C#. On the C# side, there are classes with members, who's types are probably going to be either Strings, Ints, or lists of Strings/Ints, or lists of other objects.
I'd like to have the same types on the Haskell side.
It would be nice if I could just magically pass one of these C# types to Haskell and on the Haskell side it will appear as a Haskell type
I assume what I'll have to do is serialise the type on the C# side and deserialise on the Haskell side.
C# allows one to serialise any data type to XML. Haskell has plenty of serialisation libraries as well.
However, the problem I presume is that if I just serialise to XML on the C# side, and deserialise from XML on the Haskell side, if my types are just slightly different, or even if the exact serialisers/deserialises represent their data in different ways, it isn't going to work.
It seems like passing complex data to/from Haskell may be a common problem other people experience, so I'm looking for any suggestions on a clean way of doing this.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

I haven't used it, but https://github.com/tim-m89/Salsa could be
interesting. (found via
https://wiki.haskell.org/Common_Language_Runtime)
cheers
mark
On Mon, Mar 12, 2018 at 7:06 PM, Clinton Mead
Hi All
I want to integrate Haskell into an existing C# project, initially by creating one C# class that basically does all it's "work" in Haskell (and just provides a C# interface).
There will be a few types passed in and out of this Haskell module from/to C#. On the C# side, there are classes with members, who's types are probably going to be either Strings, Ints, or lists of Strings/Ints, or lists of other objects.
I'd like to have the same types on the Haskell side.
It would be nice if I could just magically pass one of these C# types to Haskell and on the Haskell side it will appear as a Haskell type
I assume what I'll have to do is serialise the type on the C# side and deserialise on the Haskell side.
C# allows one to serialise any data type to XML. Haskell has plenty of serialisation libraries as well.
However, the problem I presume is that if I just serialise to XML on the C# side, and deserialise from XML on the Haskell side, if my types are just slightly different, or even if the exact serialisers/deserialises represent their data in different ways, it isn't going to work.
It seems like passing complex data to/from Haskell may be a common problem other people experience, so I'm looking for any suggestions on a clean way of doing this.
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
-- A UNIX signature isn't a return address, it's the ASCII equivalent of a black velvet clown painting. It's a rectangle of carets surrounding a quote from a literary giant of weeniedom like Heinlein or Dr. Who. -- Chris Maeda
participants (5)
-
Clinton Mead
-
Jefferson Carpenter
-
Mark Wotton
-
Neil Mayhew
-
Patrick Chilton