Open vrom911 opened 5 years ago
I vote to create one bi-directional pattern for easy construction/deconstruction and also a pattern for the empty list
{-# LANGUAGE PatternSynonyms, ViewPatterns, RecordWildCards #-} infixr 5 :- pattern x :- xs <- (uncons->(x,xs)) where x :- Slist{..} = Slist (x : sList) (sSize + 1) pattern Nil = Slist [] 0
Usage:
myList = 1 :- 2 :- 3 :- Nil head' (x:-_) = x tail' (_:-x) = x sum' (x:-xs) = x + sum' xs sum' Nil = 0
@BlackCapCoder the patterns you're suggesting don't capture the size in any way; however, this issue is created because I was working a lot with pattern-matching on the size.
I vote to create one bi-directional pattern for easy construction/deconstruction and also a pattern for the empty list
Usage: