I have to say I am struggling to implement this and I think it’s all too abstract for me at my current level of knowledge.
Although I’ve explored further with this, the minimal problem is reproduced by this code, which is almost verbatim from the parent post:
type Probability = Float
class Monoid r => Cone r where
scale :: Probability -> r -> r
-- Monoid to be understood additively
type Dist a = forall r. Cone r => (a -> r) -> r
pure :: a -> Dist a
pure a = \b -> b a
bind :: (a -> Dist b) -> Dist a -> Dist b
bind k m = \b -> m (flip k b)
This gives the following error:
olf.hs:13:26: error: [GHC-83865]
• Couldn't match type: forall r1. Cone r1 => (b -> r1) -> r1
with: (b -> r) -> r
Expected: a -> (b -> r) -> r
Actual: a -> Dist b
• In the first argument of ‘flip’, namely ‘k’
In the first argument of ‘m’, namely ‘(flip k b)’
In the expression: m (flip k b)
• Relevant bindings include
b :: b -> r (bound at olf.hs:13:13)
k :: a -> Dist b (bound at olf.hs:13:6)
bind :: (a -> Dist b) -> Dist a -> Dist b (bound at olf.hs:13:1)
|
13 | bind k m = \b -> m (flip k b)
| ^
Maybe “maximally free” translates to “not actually typeable”, I don’t know!
It’s unclear to me how the Dist type is supposed to work, frankly, even the pure
function.
As I say, I’ve explored further and keep failing, presumably due my misunderstanding of the model that’s being proposed.
Thanks for any help anyone can offer!