Skip to content

Instantly share code, notes, and snippets.

@RyanGlScott
Created June 29, 2016 23:28
Show Gist options
  • Save RyanGlScott/b8c41aed9e00cf448fb068deebaf170a to your computer and use it in GitHub Desktop.
Save RyanGlScott/b8c41aed9e00cf448fb068deebaf170a to your computer and use it in GitHub Desktop.
module Read where
-- import Text.Read
readsData :: (String -> ReadS a) -> Int -> ReadS a
readsData reader d =
readParen (d > 10) $ \ r -> [res | (kw,s) <- lex r, res <- reader kw s]
readsUnaryWith :: (Int -> ReadS a) -> String -> (a -> t) -> String -> ReadS t
readsUnaryWith rp name cons kw s =
[(cons x,t) | kw == name, (x,t) <- rp 11 s]
readUnaryWith :: ReadPrec a -> String -> (a -> t) -> String -> ReadPrec t
readUnaryWith = undefined
readsBinaryWith :: (Int -> ReadS a) -> (Int -> ReadS b) ->
String -> (a -> b -> t) -> String -> ReadS t
readsBinaryWith rp1 rp2 name cons kw s =
[(cons x y,u) | kw == name, (x,t) <- rp1 11 s, (y,u) <- rp2 11 t]
readBinaryWith :: ReadPrec a -> ReadPrec b ->
String -> (a -> b -> t) -> String -> ReadPrec t
readBinaryWith = undefined
liftReadsPrec2Either :: (Int -> ReadS a) -> ReadS [a]
-> (Int -> ReadS b) -> ReadS [b]
-> Int -> ReadS (Either a b)
liftReadsPrec2Either rp1 _ rp2 _ = readsData $
readsUnaryWith rp1 "Left" Left `mappend`
readsUnaryWith rp2 "Right" Right
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment