| 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 | 
 | 42 |  * i8 -> Data.Word.Word8 | 
 | 43 |  * i16 -> Data.Int.Int16 | 
 | 44 |  * i32 -> Data.Int.Int32 | 
 | 45 |  * i64 -> Data.Int.Int64 | 
 | 46 |  * string -> String | 
 | 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 |  | 
 | 55 | Structs | 
 | 56 | ======= | 
 | 57 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 58 | 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] | 59 | fields are Maybe types. | 
 | 60 |  | 
 | 61 | Exceptions | 
 | 62 | ========== | 
 | 63 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 64 | Identical to structs. Throw them with throwDyn. Catch them with catchDyn. | 
| Bryan Duxbury | 6a3705c | 2009-04-07 23:23:39 +0000 | [diff] [blame] | 65 |  | 
 | 66 | Client | 
 | 67 | ====== | 
 | 68 |  | 
| Anthony F. Molinaro | fa6eaca | 2010-09-27 17:33:47 +0000 | [diff] [blame] | 69 | 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] | 70 | deal with inheritance. | 
 | 71 |  | 
 | 72 | Interface | 
 | 73 | ========= | 
 | 74 |  | 
 | 75 | You should only have to import the last one in the chain of inheritors. To make | 
 | 76 | an interface, declare a label: | 
 | 77 |  | 
 | 78 |   data MyIface = MyIface | 
 | 79 |  | 
 | 80 | and then declare it an instance of each iface class, starting with the superest | 
 | 81 | class and proceding down (all the while defining the methods).  Then pass your | 
 | 82 | label to process as the handler. | 
 | 83 |  | 
 | 84 | Processor | 
 | 85 | ========= | 
 | 86 |  | 
 | 87 | Just a function that takes a handler label, protocols. It calls the | 
 | 88 | superclasses process if there is a superclass. | 
| iproctor | ff8eb92 | 2007-07-25 19:06:13 +0000 | [diff] [blame] | 89 |  |