I agree, but with a slight difference. Since I am so lazy, if Binary
fits, like 80% of my requirements, for example this case, only
[String] is not OK. I'd like to reuse it with a little modification
made by myself, rather than re-write almost the whole of it.
But for Data.Binary, I think this
Magicloud Magiclouds schrieb:
Hi,
I am using Data.Binary which defined instance Binary a = Binary
[a]. Now I need to define instance Binary [String] to make
something special for string list.
How to make it work? I looked into the chapter of
overlappinginstances, nothing works.
Hello,
I only use the 'Binary' class when I don't care about the specifics of
the serialization format, only that it be reasonably fast, compact and
stable.
When I need to comply with some particular format I use the functions
in Data.Binary.Builder and Data.Binary.Get directly. Sometimes I make
Hi,
I am using Data.Binary which defined instance Binary a = Binary
[a]. Now I need to define instance Binary [String] to make
something special for string list.
How to make it work? I looked into the chapter of
overlappinginstances, nothing works.
--
竹密岂妨流水过
山高哪阻野云飞
Am 05.01.2011 09:24, schrieb Magicloud Magiclouds:
Hi,
I am using Data.Binary which defined instance Binary a = Binary
[a]. Now I need to define instance Binary [String] to make
something special for string list.
How to make it work? I looked into the chapter of
overlappinginstances,
Hello,
{-# LANGUAGE OverlappingInstances, FlexibleInstances #-}
import Data.Binary
instance Binary [String] where
get = undefined
put = undefined
works fine here on GHC 6.12.3. That being said, it would be safer
perhaps to add a newtype around [String] so you can
You can't. If you have special semantics for [String], then it is not
really a [String], it is something else. So let the type system know
that:
newtype SomethingElse = SomethingElse [String]
instance Binary SomethingElse where
...
On Wed, Jan 5, 2011 at 1:24 AM, Magicloud Magiclouds
You have two choices (other people have enumerated the first while I
was typing):
First choice:
Wrap your Stringlist with a newtype:
newtype StringList = StringList [String]
The downside of this your code gets polluted with the newtype.
Second choice:
Write special putStringList and
Steffen Schuldenzucker:
Sure. GHC would prompt that.
Jasper Van der Jeugt:
Not working with ghc7. But there sure are some threads about this
kind of things. I do not know if this is a bug of 6.* or 7, either.
Luke Palmer:
Sorry, by special, I meant, for example, [a, b] will be ab by