From b601561e38884d6f729c3a86eb0ec4445aea6155 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Wed, 10 Apr 2024 18:26:34 +0200 Subject: Improve FAlternative class --- src/Control/FAlternative.hs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/Control/FAlternative.hs') diff --git a/src/Control/FAlternative.hs b/src/Control/FAlternative.hs index 473b3df..8fd35c3 100644 --- a/src/Control/FAlternative.hs +++ b/src/Control/FAlternative.hs @@ -1,6 +1,8 @@ {-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE QuantifiedConstraints #-} +{-# LANGUAGE ScopedTypeVariables #-} +{-# LANGUAGE TypeApplications #-} module Control.FAlternative where import Data.List.NonEmpty (NonEmpty(..)) @@ -24,7 +26,11 @@ class (forall fail. Applicative (f fail)) => FAlternative f where faempty :: f 'Fallible a (<|>>) :: f 'Fallible a -> f fail a -> f fail a noFail :: f 'Infallible a -> f fail a - toFallible :: KnownFallible fail => f fail a -> f 'Fallible a + +toFallible :: forall fail f a. (FAlternative f, KnownFallible fail) => f fail a -> f 'Fallible a +toFallible = case knownFallible @fail of + SFallible -> id + SInfallible -> noFail faasum :: FAlternative f => [f 'Fallible a] -> f fail a -> f fail a faasum l p = foldr (<|>>) p l -- cgit v1.2.3-70-g09d2