I think you want toDyn , not fromDynamic . So do it slowly:
mkDyn :: Typeable a => ((a -> IO ()) -> IO ()) -> (Dynamic -> IO ()) -> IO () mkDyn kf = ...
Our return type must be IO () , and we can get this either by calling k or f . Calling f does not help us much, because we somehow implement Dynamic , but we cannot do this (reasonably) from k . Therefore, we want to call k . k needs another function as an argument, so let's start like this:
mkDyn kf = k (\a -> ...)
So, the argument of the function Typeable a => a -> IO () . We do not have a function of this type, but we have a function of type Dynamic -> IO () . Due to Typeable limitation Typeable we can use toDyn to turn our a into Dynamic and get:
mkDyn kf = k (\a -> f (toDyn a))
There are simpler implementations (like return () or k (\a -> return ()) , but that seems to make sense.
nominolo
source share