Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create patterns for smooth pattern-matching #2

Open
vrom911 opened this issue Mar 28, 2019 · 2 comments
Open

Create patterns for smooth pattern-matching #2

vrom911 opened this issue Mar 28, 2019 · 2 comments
Labels
enhancement New feature or request

Comments

@vrom911
Copy link
Member

vrom911 commented Mar 28, 2019

No description provided.

@vrom911 vrom911 added the enhancement New feature or request label Mar 28, 2019
@BlackCapCoder
Copy link

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

@vrom911
Copy link
Member Author

vrom911 commented Apr 9, 2019

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants