[ 
https://issues.apache.org/jira/browse/THRIFT-906?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12912582#action_12912582
 ] 

Christian Lavoie commented on THRIFT-906:
-----------------------------------------

For someone starting from scratch, it'd be no more or less annoying that using 
Int: the natural integral type in Haskell is Integer (multiprecision integral), 
not Int (or Int16, Int32, ...).

To patch existing code...

Logically speaking, they'd have to re-type every bit of code using stuff 
imported from the gen-hs/* files. This is not has horrible as it sounds, you 
can mechanically get everything to compile again (and I suspect work about as 
well as before my patch) by liberal use of "fromIntegral" for the integral 
types:

myStruct {
  f_myStruct_field1 = foo,
  f_myStruct_field2 = bar }

would become

myStruct {
  f_myStruct_field1 = fromIntegral foo,
  f_myStruct_field2 = fromIntegral bar }

The problem is that Int in Haskell is only guaranteed to be (at least) 30 bits 
wide [1], not 16, 32 or 64, so conversions to/from are potentially lossy. Using 
the fromIntegral trick doesn't fix (or, I believe, worsen) the lossiness. The 
"right" thing to do is to handle bit-width in w\e way is appropriate for your 
code; how complex is that depends on the code.

Handling the binary change (String -> DBL.ByteString) is a bit more annoying, 
but since using String means Haskell tries to parse your binary data as unicode 
somehow (String in Haskell is really [Char], which is builtin-list of Unicode 
characters; I'm still trying to figure out what encoding the thrift bindings 
actually do), which almost certainly garbles whatever binary you had. Long 
story short, I suspect nobody uses that, since it's corrupts a fair chunk of 
data in or out.

[1] see 
http://www.haskell.org/ghc/docs/6.12.2/html/libraries/base-4.2.0.1/Prelude.html#t%3AInt
 -- short version is "implementation dependant" and "at least able to represent 
[-2^29 .. 2^29-1]".

> Improve type mappings
> ---------------------
>
>                 Key: THRIFT-906
>                 URL: https://issues.apache.org/jira/browse/THRIFT-906
>             Project: Thrift
>          Issue Type: New Feature
>          Components: Haskell - Compiler, Haskell - Library
>         Environment: Darwin -- 10.4.0 Darwin Kernel Version 10.4.0: Fri Apr 
> 23 18:28:53 PDT 2010; root:xnu-1504.7.4~1/RELEASE_I386 i386
> The Glorious Glasgow Haskell Compilation System, version 6.12.3
>            Reporter: Christian Lavoie
>             Fix For: 0.5, 0.6, 0.7
>
>         Attachments: thrift-improved-haskell-type-mappings.patch
>
>
> The current haskell type mappings are awkward and error prone to work with:
> binary -> String
> string -> String
> byte -> Int
> i16 -> Int
> i32 -> Int
> i64 -> Int
> This patch updates the mappings to the canonical types of the correct length 
> in Haskell:
> binary -> Data.ByteString.Lazy.ByteString
> string -> String
> byte -> Data.Word.Word8
> i16 -> Data.Int.Int16
> i32 -> Data.Int.Int32
> i64 -> Data.Int.Int64
> THIS BREAKS EXISTING CODE. It is, however, very arguably broken already.
> For convenience of patching, this patch is a superset of THRIFT-743.
> Thoughts?

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.

Reply via email to