Skip to content

Instantly share code, notes, and snippets.

@Lysxia
Created May 24, 2025 06:35
Show Gist options
  • Save Lysxia/d46f4dddcfdb2267e56d42b05dfc2fca to your computer and use it in GitHub Desktop.
Save Lysxia/d46f4dddcfdb2267e56d42b05dfc2fca to your computer and use it in GitHub Desktop.
-- src/A.hs
{-# LANGUAGE ScopedTypeVariables, TypeApplications #-}
module A where
import Control.Monad.Trans.State
import Data.Coerce
mapAccumLM :: forall a b c m t.
(Traversable t, Monad m) => (b -> a -> m (c, a)) -> t b -> a -> m (t c, a)
mapAccumLM f = coerce (traverse @t @(StateT a m) @b @c) f
-- src/B.hs
{-# LANGUAGE ScopedTypeVariables #-}
{-# OPTIONS_GHC -ddump-simpl -dsuppress-all -ddump-to-file #-}
module B where
import Control.Monad.Trans.Reader
import A
mapAccumLList :: forall a b c x.
(b -> a -> ReaderT x Maybe (c, a)) -> [b] -> a -> ReaderT x Maybe ([c], a)
mapAccumLList = mapAccumLM
cabal-version: 3.0
name: t
version: 0.1.0.0
build-type: Simple
common warnings
ghc-options: -Wall
library
import: warnings
exposed-modules: A, B
build-depends: base, transformers
hs-source-dirs: src
default-language: Haskell2010
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment