Skip to content

Instantly share code, notes, and snippets.

@caasi
Created July 8, 2018 01:20
Show Gist options
  • Save caasi/bfc2cba0a2706c315a07751e22808197 to your computer and use it in GitHub Desktop.
Save caasi/bfc2cba0a2706c315a07751e22808197 to your computer and use it in GitHub Desktop.
module Main where
import Data.Functor.Constant
import Data.Bifunctor
data Riap b a = Riap a b
-- data PreList a b
-- = Nil
-- | PreList a b
newtype PreList a b = PreList (Either (Constant () a) (Riap b a))
instance Functor f => Functor (Riap (f b)) where
fmap f (Riap a b) = Riap (f a) (fmap f b)
instance Bifunctor PreList where
bimap f g (PreList (Left c)) = PreList (Left (fmap f c))
bimap f g (PreList (Right op)) = PreList (Right (fmap g op))
main :: IO ()
main = undefined
@caasi
Copy link
Author

caasi commented Jul 8, 2018

更正, PreList a b 不用是個 Functor

module Main where

import Data.Functor.Constant
import Data.Bifunctor

-- data PreList a b
--   = Nil
--   | PreList a b
newtype PreList a b = PreList (Either (Constant () a) (a, b))

instance Bifunctor PreList where
  bimap f g (PreList (Left c)) = PreList (Left (fmap f c))
  bimap f g (PreList (Right (a, b))) = PreList (Right ((f a), (g b)))

main :: IO ()
main = undefined

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment