[Haskell-cafe] Re: Type classes
Oscar Picasso
oscarpicasso at gmail.com
Sat Dec 27 01:10:54 EST 2008
Forget it. It's more clear reading further.
Sorry for the noise.
On Sat, Dec 27, 2008 at 1:02 AM, Oscar Picasso <oscarpicasso at gmail.com>wrote:
> From Real World Haskell:
>
> data JValue = JString String
> | JNumber Double
> | JBool Bool
> | JNull
> | JObject [(String, JValue)]
> | JArray [JValue]
> deriving (Eq, Ord, Show)
>
> ....
> type JSONError = String
>
> class JSON a where
> toJValue :: a -> JValue
> fromJValue :: JValue -> Either JSONError a
>
> instance JSON JValue where
> toJValue = id -- Really ?
> fromJValue = Right
>
> Now, instead of applying a constructor like JNumber to a value to wrap it,
>> we apply the toJValue function. If we change a value's type, the compiler
>> will choose a suitable implementation of toJValue to use with it.
>
>
> Actually it does not work. And I don't see how it could with this toJValue
> implementation. Is it possible to make it work by providing another
> implementation?
>
> Oscar
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.haskell.org/pipermail/haskell-cafe/attachments/20081227/6a3d2dba/attachment.htm
More information about the Haskell-Cafe
mailing list