| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 1 | Haskell Thrift Bindings | 
 | 2 |  | 
| Bryan Duxbury | def30a6 | 2009-04-08 00:19:37 +0000 | [diff] [blame] | 3 | License | 
 | 4 | ======= | 
 | 5 |  | 
 | 6 | Licensed to the Apache Software Foundation (ASF) under one | 
 | 7 | or more contributor license agreements. See the NOTICE file | 
 | 8 | distributed with this work for additional information | 
 | 9 | regarding copyright ownership. The ASF licenses this file | 
 | 10 | to you under the Apache License, Version 2.0 (the | 
 | 11 | "License"); you may not use this file except in compliance | 
 | 12 | with the License. You may obtain a copy of the License at | 
 | 13 |  | 
 | 14 |   http://www.apache.org/licenses/LICENSE-2.0 | 
 | 15 |  | 
 | 16 | Unless required by applicable law or agreed to in writing, | 
 | 17 | software distributed under the License is distributed on an | 
 | 18 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | 
 | 19 | KIND, either express or implied. See the License for the | 
 | 20 | specific language governing permissions and limitations | 
 | 21 | under the License. | 
 | 22 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 23 | Compile | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 24 | ======= | 
| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 25 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 26 | Use Cabal to compile and install; ./configure uses Cabal underneath, and that | 
 | 27 | path is not yet well tested. Thrift's library and generated code should compile | 
 | 28 | with pretty much any GHC extensions or warnings you enable (or disable). | 
 | 29 | Please report this not being the case as a bug on | 
 | 30 | https://issues.apache.org/jira/secure/CreateIssue!default.jspa | 
| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 31 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 32 | Chances you'll need to muck a bit with Cabal flags to install Thrift: | 
| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 33 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 34 | CABAL_CONFIGURE_FLAGS="--user" ./configure | 
| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 35 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 36 | Base Types | 
 | 37 | ========== | 
| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 38 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 39 | The mapping from Thrift types to Haskell's is: | 
| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 40 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 41 |  * double -> Double | 
| Anthony F. Molinaro | 687c412 | 2010-10-05 16:47:52 +0000 | [diff] [blame] | 42 |  * byte -> Data.Word.Word8 | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 43 |  * i16 -> Data.Int.Int16 | 
 | 44 |  * i32 -> Data.Int.Int32 | 
 | 45 |  * i64 -> Data.Int.Int64 | 
| Roger Meier | 6849f20 | 2012-05-18 07:35:19 +0000 | [diff] [blame] | 46 |  * string -> Text | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 47 |  * binary -> Data.ByteString.Lazy | 
 | 48 |  * bool -> Boolean | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 49 |  | 
 | 50 | Enums | 
 | 51 | ===== | 
 | 52 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 53 | Become Haskell 'data' types. Use fromEnum to get out the int value. | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 54 |  | 
| Roger Meier | 6849f20 | 2012-05-18 07:35:19 +0000 | [diff] [blame] | 55 | Lists | 
 | 56 | ===== | 
 | 57 |  | 
 | 58 | Become Data.Vector.Vector from the vector package. | 
 | 59 |  | 
 | 60 | Maps and Sets | 
 | 61 | ============= | 
 | 62 |  | 
 | 63 | Become Data.HashMap.Strict.Map and Data.HashSet.Set from the | 
 | 64 | unordered-containers package. | 
 | 65 |  | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 66 | Structs | 
 | 67 | ======= | 
 | 68 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 69 | Become records. Field labels are ugly, of the form f_STRUCTNAME_FIELDNAME. All | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 70 | fields are Maybe types. | 
 | 71 |  | 
 | 72 | Exceptions | 
 | 73 | ========== | 
 | 74 |  | 
| Roger Meier | 6849f20 | 2012-05-18 07:35:19 +0000 | [diff] [blame] | 75 | Identical to structs. Use them with throw and catch from Control.Exception. | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 76 |  | 
 | 77 | Client | 
 | 78 | ====== | 
 | 79 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 80 | Just a bunch of functions. You may have to import a bunch of client files to | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 81 | deal with inheritance. | 
 | 82 |  | 
 | 83 | Interface | 
 | 84 | ========= | 
 | 85 |  | 
 | 86 | You should only have to import the last one in the chain of inheritors. To make | 
 | 87 | an interface, declare a label: | 
 | 88 |  | 
 | 89 |   data MyIface = MyIface | 
 | 90 |  | 
 | 91 | and then declare it an instance of each iface class, starting with the superest | 
 | 92 | class and proceding down (all the while defining the methods).  Then pass your | 
 | 93 | label to process as the handler. | 
 | 94 |  | 
 | 95 | Processor | 
 | 96 | ========= | 
 | 97 |  | 
 | 98 | Just a function that takes a handler label, protocols. It calls the | 
 | 99 | superclasses process if there is a superclass. |