Skip to content

Instantly share code, notes, and snippets.

@viercc
Last active December 8, 2023 04:20
Show Gist options
  • Save viercc/fe4e9ce2f8f84bbd8109b3691d40b44f to your computer and use it in GitHub Desktop.
Save viercc/fe4e9ce2f8f84bbd8109b3691d40b44f to your computer and use it in GitHub Desktop.
aaaaaa

(1)

-- m は暗黙に量化されている
{-
action :: forall m. MonadError OutOfRange m => m Int
-}
action :: MonadError OutOfRange m => m Int
action = undefined

foo :: Either OutOfRange Int -> Either OutOfRange Int -> Either OutOfRange Int
foo = undefined

result :: Either OutOfRange Int
result = foo (_hole action) (_bar action)
  -- _hole の型は、ユニフィケーション変数m1を使って
  -- _hole :: m1 Int -> Either OutOfRange Int
  -- _bar の型は、ユニフィケーション変数m2を使って
  -- _bar :: m2 Int -> Either OutOfRange Int
  --

(2)

{-# LANGUAGE ScopedTypeVaraibles #-}
{-# LANGUAGE AllowAmbiguousTypes #-}

foo :: Either OutOfRange Int -> Either OutOfRange Int -> Either OutOfRange Int
foo = undefined

result :: forall m. MonadError OutOfRange m => Either OutOfRange Int
result = foo (_hole action) (bar action)
  where
    action :: m Int
    action = undefined
    
    bar :: m Int -> Either OutOfRange Int
    bar = undefined

(3)

{-# LANGUAGE ExplicitForall #-}
{-# LANGUAGE MonoLocalBinds #-}

foo :: Either OutOfRange Int -> Either OutOfRange Int -> Either OutOfRange Int
foo = undefined

genericAction :: forall m. MonadError OutOfRange m => m Int
genericFoo :: forall m. m Int -> Either OutOfRange Int

result :: Either OutOfRange Int
result = foo (_hole action) (bar action)
  where
    -- m はユニフィケーション変数
    -- action :: m Int
    action = genericAction
    -- bar :: m Int -> Either OutOfRange Int
    bar = genericFoo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment