Register GObject subtype using bindings-gobject

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
module Main
where

import Foreign
import Foreign.C
import Bindings.GObject

main :: IO ()
main = do
  c'g_type_init

  -- query parent type size
  (classSize, instanceSize) <- with (C'GTypeQuery 0 nullPtr 0 0) $ \tq -> do
    c'g_type_query c'G_TYPE_OBJECT tq
    q <- peek tq
    return (c'GTypeQuery'class_size q, c'GTypeQuery'instance_size q)

  classInit <- mk'GClassInitFunc $ \_ _ -> do
    -- class initialization goes here
    return ()
  instanceInit <- mk'GInstanceInitFunc $ \_ _ -> do
    -- instance initialization goes here
    return ()

  myObType <- withCString "MyOb" $ \typeName ->
    c'g_type_register_static_simple c'G_TYPE_OBJECT
                                    typeName
                                    classSize
                                    classInit
                                    instanceSize
                                    instanceInit
                                    0

  -- create instance of MyOb
  myOb <- c'g_object_newv myObType 0 nullPtr

  -- delete it
  c'g_object_unref myOb

  return ()
18:44: Error: Redundant do
Found:
do return ()
Why not:
return ()
21:50: Error: Redundant do
Found:
do return ()
Why not:
return ()