Haskell shying away from probabilistic data structures?

前端 未结 7 869
时光说笑
时光说笑 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"
    

提交回复
热议问题