Skip to content

Instantly share code, notes, and snippets.

@christiaanb
Created April 20, 2016 08:26
Show Gist options
  • Save christiaanb/ad5b7315142d0b0ade4b50d53562c0a3 to your computer and use it in GitHub Desktop.
Save christiaanb/ad5b7315142d0b0ade4b50d53562c0a3 to your computer and use it in GitHub Desktop.
{-# LANGUAGE PatternSynonyms, ViewPatterns, TypeFamilies #-}
module Pat1 (Vec(Nil,(:>)), pattern (:>)) where
import qualified Control.Lens as Lens hiding (pattern (:>))
newtype Vec a = Vec {unvec :: [a]}
pattern Nil :: Vec a
pattern Nil = Vec []
pattern (:>) :: a -> Vec a -> Vec a
pattern (:>) x xs <- ((\ys -> (head $ unvec ys,Vec . tail $ unvec ys)) -> (x,xs))
where
(:>) x xs = Vec (x:unvec xs)
infixl 5 :>
type instance Lens.Index (Vec a) = Int
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment