Quick actions

cmd+k|ctrl+k

Navigation

Languages

Robust

Snippet info

Language

Haskell

Visibility

public

Author

rightfold

Created

2017-08-22T12:52:08Z

Updated

2017-08-22T13:06:54Z

{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}

module Main (main) where

import Control.Monad.Free (Free, foldFree)

recovering :: a -> a
recovering = id

class Robust f where
  isIdempotent :: f a -> Bool

foldRobust :: forall f g a. Robust f => Monad g => (forall x. f x -> g x) -> Free f a -> g a
foldRobust interpret = foldFree interpret'
  where
  interpret' :: f x -> g x
  interpret' action
    | isIdempotent action = recovering $ interpret action
    | otherwise = interpret action

main :: IO ()
main = putStrLn "Hello World!"
INFO