Skip to content

Instantly share code, notes, and snippets.

@ThoNohT
Created November 12, 2022 18:39
Show Gist options
  • Save ThoNohT/8af39ad731835f48cc3c6bd246a19285 to your computer and use it in GitHub Desktop.
Save ThoNohT/8af39ad731835f48cc3c6bd246a19285 to your computer and use it in GitHub Desktop.
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
import qualified Data.List as L
class Uncons l a where
uncons :: l -> Maybe (a, l)
instance Uncons [a] a where uncons = L.uncons
newtype Parser l a = Parser {runParser :: l -> Maybe (a, l)} deriving (Functor)
end :: forall l a. Uncons l a => Parser l ()
end = Parser $ \input -> case uncons input of
Just _ -> Nothing
Nothing -> Just ((), input)
main = putStrLn "Hello, World!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment