Questions tagged [as-pattern]
7 questions
17
votes
1 answer
Besides as-pattern, what else can @ mean in Haskell?
I am studying Haskell currently and try to understand a project that uses Haskell to implement cryptographic algorithms. After reading Learn You a Haskell for Great Good online, I begin to understand the code in that project. Then I found I am stuck…

SigurdW
- 173
- 4
9
votes
1 answer
Erlang's equivalent of Haskell's as-patterns
How can I write in Erlang an equivalent of this Haskell snippet?
name@(x:xs)

ciembor
- 7,189
- 13
- 59
- 100
7
votes
4 answers
Why does adding an as-pattern to a working function cause compilation errors?
Here's the standard Functor instance for Either a:
instance Functor (Either a) where
fmap _ (Left x) = Left x
fmap f (Right y) = Right (f y)
adding in an as-pattern causes compilation errors when loading into GHCi:
instance Functor…

Matt Fenwick
- 48,199
- 22
- 128
- 192
2
votes
1 answer
as-pattern and list pattern matching question
Exercise 2 of this pdf reads:
Once we have the digits in the proper order, we need to double every
other one. Define a function
doubleEveryOther :: [Integer] -> [Integer]
Remember that doubleEveryOther should double every other
number beginning…

machismo
- 21
- 2
2
votes
1 answer
OCAML confuses defined type with definition?
I am working on an assignment for converting Regular Expressions into an NFA and for converting an NFA to DFA in OCAML. I have been writing my code in a separate file in order to test each "function" individually, but I have come across a problem…

Code Doggo
- 2,146
- 6
- 33
- 58
2
votes
2 answers
Functionality of as-pattern, non overlapping pattern through 'as pattern'
I am new to functional programming and haskell in particular and have two questions abound as-pattern and the reduction of overlappings through using it.
Giving the following code example:
last1 :: [a] -> a
last1 [x] = …

froehli
- 904
- 1
- 11
- 35
1
vote
0 answers
Scala's equivalent to Haskell's as-patterns in pattern matching?
I have pattern matching in Scala with a long case of which I use a large part. Can I name the part of the case so I don't have to rewrite the whole expression?
Example:
x match {
case (("def", symPos) :: defRest, defPos) :: rest =>
val…

matj1
- 158
- 1
- 11