diff options
author | Alberto Ruiz <aruiz@um.es> | 2015-06-19 13:55:39 +0200 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2015-06-19 13:55:39 +0200 |
commit | db50bc11dafa6834a4367427156306674063ed6b (patch) | |
tree | 721e9d0235168be1d0ebb2bd1dd254a66251f274 /packages/base/src/Internal/Devel.hs | |
parent | 7f9c7b5adf8f05653d15f19358f41c1916e8db70 (diff) |
removed the annoying appN adapter for the foreign functions.
replaced by several overloaded app variants in the style of
the module Internal.Foreign contributed by Mike Ledger.
Diffstat (limited to 'packages/base/src/Internal/Devel.hs')
-rw-r--r-- | packages/base/src/Internal/Devel.hs | 89 |
1 files changed, 32 insertions, 57 deletions
diff --git a/packages/base/src/Internal/Devel.hs b/packages/base/src/Internal/Devel.hs index b8e04ef..4be0afd 100644 --- a/packages/base/src/Internal/Devel.hs +++ b/packages/base/src/Internal/Devel.hs | |||
@@ -1,4 +1,5 @@ | |||
1 | {-# LANGUAGE TypeOperators #-} | 1 | {-# LANGUAGE TypeOperators #-} |
2 | {-# LANGUAGE TypeFamilies #-} | ||
2 | 3 | ||
3 | -- | | 4 | -- | |
4 | -- Module : Internal.Devel | 5 | -- Module : Internal.Devel |
@@ -16,68 +17,14 @@ import Foreign.C.Types ( CInt ) | |||
16 | --import Foreign.Storable.Complex () | 17 | --import Foreign.Storable.Complex () |
17 | import Foreign.Ptr(Ptr) | 18 | import Foreign.Ptr(Ptr) |
18 | import Control.Exception as E ( SomeException, catch ) | 19 | import Control.Exception as E ( SomeException, catch ) |
19 | 20 | import Internal.Vector(Vector,avec,arrvec) | |
21 | import Foreign.Storable(Storable) | ||
20 | 22 | ||
21 | -- | postfix function application (@flip ($)@) | 23 | -- | postfix function application (@flip ($)@) |
22 | (//) :: x -> (x -> y) -> y | 24 | (//) :: x -> (x -> y) -> y |
23 | infixl 0 // | 25 | infixl 0 // |
24 | (//) = flip ($) | 26 | (//) = flip ($) |
25 | 27 | ||
26 | -- hmm.. | ||
27 | ww2 w1 o1 w2 o2 f = w1 o1 $ w2 o2 . f | ||
28 | ww3 w1 o1 w2 o2 w3 o3 f = w1 o1 $ ww2 w2 o2 w3 o3 . f | ||
29 | ww4 w1 o1 w2 o2 w3 o3 w4 o4 f = w1 o1 $ ww3 w2 o2 w3 o3 w4 o4 . f | ||
30 | ww5 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 f = w1 o1 $ ww4 w2 o2 w3 o3 w4 o4 w5 o5 . f | ||
31 | ww6 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 f = w1 o1 $ ww5 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 . f | ||
32 | ww7 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 f = w1 o1 $ ww6 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 . f | ||
33 | ww8 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 f = w1 o1 $ ww7 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 . f | ||
34 | ww9 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 f = w1 o1 $ ww8 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 . f | ||
35 | ww10 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 w10 o10 f = w1 o1 $ ww9 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 w10 o10 . f | ||
36 | |||
37 | type Adapt f t r = t -> ((f -> r) -> IO()) -> IO() | ||
38 | |||
39 | type Adapt1 f t1 = Adapt f t1 (IO CInt) -> t1 -> String -> IO() | ||
40 | type Adapt2 f t1 r1 t2 = Adapt f t1 r1 -> t1 -> Adapt1 r1 t2 | ||
41 | type Adapt3 f t1 r1 t2 r2 t3 = Adapt f t1 r1 -> t1 -> Adapt2 r1 t2 r2 t3 | ||
42 | type Adapt4 f t1 r1 t2 r2 t3 r3 t4 = Adapt f t1 r1 -> t1 -> Adapt3 r1 t2 r2 t3 r3 t4 | ||
43 | type Adapt5 f t1 r1 t2 r2 t3 r3 t4 r4 t5 = Adapt f t1 r1 -> t1 -> Adapt4 r1 t2 r2 t3 r3 t4 r4 t5 | ||
44 | type Adapt6 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 = Adapt f t1 r1 -> t1 -> Adapt5 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 | ||
45 | type Adapt7 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 = Adapt f t1 r1 -> t1 -> Adapt6 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 | ||
46 | type Adapt8 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 = Adapt f t1 r1 -> t1 -> Adapt7 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 | ||
47 | type Adapt9 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9 = Adapt f t1 r1 -> t1 -> Adapt8 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9 | ||
48 | type Adapt10 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9 r9 t10 = Adapt f t1 r1 -> t1 -> Adapt9 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9 r9 t10 | ||
49 | |||
50 | app1 :: f -> Adapt1 f t1 | ||
51 | app2 :: f -> Adapt2 f t1 r1 t2 | ||
52 | app3 :: f -> Adapt3 f t1 r1 t2 r2 t3 | ||
53 | app4 :: f -> Adapt4 f t1 r1 t2 r2 t3 r3 t4 | ||
54 | app5 :: f -> Adapt5 f t1 r1 t2 r2 t3 r3 t4 r4 t5 | ||
55 | app6 :: f -> Adapt6 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 | ||
56 | app7 :: f -> Adapt7 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 | ||
57 | app8 :: f -> Adapt8 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 | ||
58 | app9 :: f -> Adapt9 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9 | ||
59 | app10 :: f -> Adapt10 f t1 r1 t2 r2 t3 r3 t4 r4 t5 r5 t6 r6 t7 r7 t8 r8 t9 r9 t10 | ||
60 | |||
61 | app1 f w1 o1 s = w1 o1 $ \a1 -> f // a1 // check s | ||
62 | app2 f w1 o1 w2 o2 s = ww2 w1 o1 w2 o2 $ \a1 a2 -> f // a1 // a2 // check s | ||
63 | app3 f w1 o1 w2 o2 w3 o3 s = ww3 w1 o1 w2 o2 w3 o3 $ | ||
64 | \a1 a2 a3 -> f // a1 // a2 // a3 // check s | ||
65 | app4 f w1 o1 w2 o2 w3 o3 w4 o4 s = ww4 w1 o1 w2 o2 w3 o3 w4 o4 $ | ||
66 | \a1 a2 a3 a4 -> f // a1 // a2 // a3 // a4 // check s | ||
67 | app5 f w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 s = ww5 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 $ | ||
68 | \a1 a2 a3 a4 a5 -> f // a1 // a2 // a3 // a4 // a5 // check s | ||
69 | app6 f w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 s = ww6 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 $ | ||
70 | \a1 a2 a3 a4 a5 a6 -> f // a1 // a2 // a3 // a4 // a5 // a6 // check s | ||
71 | app7 f w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 s = ww7 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 $ | ||
72 | \a1 a2 a3 a4 a5 a6 a7 -> f // a1 // a2 // a3 // a4 // a5 // a6 // a7 // check s | ||
73 | app8 f w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 s = ww8 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 $ | ||
74 | \a1 a2 a3 a4 a5 a6 a7 a8 -> f // a1 // a2 // a3 // a4 // a5 // a6 // a7 // a8 // check s | ||
75 | app9 f w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 s = ww9 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 $ | ||
76 | \a1 a2 a3 a4 a5 a6 a7 a8 a9 -> f // a1 // a2 // a3 // a4 // a5 // a6 // a7 // a8 // a9 // check s | ||
77 | app10 f w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 w10 o10 s = ww10 w1 o1 w2 o2 w3 o3 w4 o4 w5 o5 w6 o6 w7 o7 w8 o8 w9 o9 w10 o10 $ | ||
78 | \a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 -> f // a1 // a2 // a3 // a4 // a5 // a6 // a7 // a8 // a9 // a10 // check s | ||
79 | |||
80 | |||
81 | 28 | ||
82 | -- GSL error codes are <= 1024 | 29 | -- GSL error codes are <= 1024 |
83 | -- | error codes for the auxiliary functions required by the wrappers | 30 | -- | error codes for the auxiliary functions required by the wrappers |
@@ -104,6 +51,11 @@ check msg f = do | |||
104 | when (err/=0) $ error (msg++": "++errorCode err) | 51 | when (err/=0) $ error (msg++": "++errorCode err) |
105 | return () | 52 | return () |
106 | 53 | ||
54 | |||
55 | -- | postfix error code check | ||
56 | infixl 0 #| | ||
57 | (#|) = flip check | ||
58 | |||
107 | -- | Error capture and conversion to Maybe | 59 | -- | Error capture and conversion to Maybe |
108 | mbCatch :: IO x -> IO (Maybe x) | 60 | mbCatch :: IO x -> IO (Maybe x) |
109 | mbCatch act = E.catch (Just `fmap` act) f | 61 | mbCatch act = E.catch (Just `fmap` act) f |
@@ -124,4 +76,27 @@ type (:>) t r = CV t r | |||
124 | type (::>) t r = OM t r | 76 | type (::>) t r = OM t r |
125 | type (..>) t r = CM t r | 77 | type (..>) t r = CM t r |
126 | 78 | ||
79 | class TransArray c | ||
80 | where | ||
81 | type Trans c b | ||
82 | type TransRaw c b | ||
83 | type Elem c | ||
84 | apply :: (Trans c b) -> c -> b | ||
85 | applyRaw :: (TransRaw c b) -> c -> b | ||
86 | applyArray :: (Ptr CInt -> Ptr (Elem c) -> b) -> c -> b | ||
87 | infixl 1 `apply`, `applyRaw`, `applyArray` | ||
88 | |||
89 | instance Storable t => TransArray (Vector t) | ||
90 | where | ||
91 | type Trans (Vector t) b = CInt -> Ptr t -> b | ||
92 | type TransRaw (Vector t) b = CInt -> Ptr t -> b | ||
93 | type Elem (Vector t) = t | ||
94 | apply = avec | ||
95 | {-# INLINE apply #-} | ||
96 | applyRaw = avec | ||
97 | {-# INLINE applyRaw #-} | ||
98 | applyArray = arrvec | ||
99 | {-# INLINE applyArray #-} | ||
100 | |||
101 | |||
127 | 102 | ||