What uses have you found for higher-rank types in Haskell?

前端 未结 4 837
青春惊慌失措
青春惊慌失措 2021-01-30 23:44

Higher rank types look like great fun. From the Haskell wikibook comes this example:

foo :: (forall a. a -> a) -> (Char,Bool)
foo f = (f \'c\', f True)
         


        
4条回答
  •  眼角桃花
    2021-01-31 00:13

    Take a look at functions like withRepoLock in the Darcs source.

    Darcs has support for multiple repository formats, and that support is expressed via a typeclass. So you can write code that is generic over repository formats. When actually reading an on-disk repository you want to dispatch to that code through some common code that figures out what format the repository is in and chooses the right typeclass instantiation.

提交回复
热议问题