Haskell shying away from probabilistic data structures?

前端 未结 7 871
时光说笑
时光说笑 2021-02-05 07:57

If you search for skips lists implemented in Haskell, you won\'t find many. It is a probabilistic data structure needing a random number generator, meaning that any of these str

相关标签:
7条回答
  • 2021-02-05 08:53

    Random generators don't require IO operations. They follow their own monadic laws (kinda derived from the State monad) and are therefore representable through a Random monad.

    In case of the skip list, you could define your own monad that's able to carry around the probabilistic computation or just use standard Random.

    demo :: Random Int
    demo = do
     let l = SkipList.empty
    
     l2 <- l `add` ("Hello", 42)
    
     return $ l2 `get` "Hello"
    
    0 讨论(0)
提交回复
热议问题