Quick actions

cmd+k|ctrl+k

Navigation

Languages

(a -> r) instance

Snippet info

Language

Haskell

Visibility

public

Author

homam

Created

2015-07-27T19:48:17Z

Updated

2015-07-27T19:48:17Z

{-# LANGUAGE FlexibleInstances #-}

class Arg a where
  collect' :: [String] -> a

-- extract to IO
instance Arg (IO ()) where
  collect' = mapM_ putStrLn

-- extract to [String]
instance Arg [String] where
  collect' = id

instance (Show a, Arg r) => Arg (a -> r) where
  collect' acc = \x -> collect' (acc ++ [show x])

collect :: Arg t => t
collect = collect' [">> "]

example1 :: [String]
example1 = collect 'a' 2 3.0 () 12

example2 :: IO ()
example2 = collect () "foo" [1,2,3] 42

main = do
    putStrLn $ concatMap id example1
    example2
INFO