Skip to main content
Filter by
Sorted by
Tagged with
1 vote
0 answers
61 views

Haskell PatternSynonyms bang strictness annotation

The User Guide comment says this is not allowed, but the explicitly bidir form is pattern StrictJust a = Just !a pattern StrictJust a <- Just !a where StrictJust !a = Just a Given that the ...
AntC's user avatar
  • 2,806
0 votes
2 answers
45 views

Conflicting definitions in pattern synonyms using a parameter more than once

Why can't I define this pattern synonym? pattern Double a = (a,a) error: • Conflicting definitions for ‘a’ Bound at: <interactive>:1:21 <interactive>:1:23 • ...
Futarimiti's user avatar
2 votes
3 answers
92 views

Factoring out common constants in pattern synonym code?

I had some code like this: newtype T = T Text pattern Alice = T "Alice" This is fine, but I was using "Alice" in other places. So I decided to factor it out like so: alice :: ...
Clinton's user avatar
  • 23.1k
2 votes
1 answer
65 views

Using pattern synonyms to abstract implementation of text type

Lets say I have: newtype Animal = Animal Text And I want to be able to pattern match on it like so: f :: Animal -> (Bool, Text) f = \case NonHuman s -> (False, s) Human -> (True, "...
Clinton's user avatar
  • 23.1k
1 vote
1 answer
55 views

How to merge nodes that represent synonyms?

Suppose I have a graph like this: Cytoscape graph The nodes 'lipid nanoparticle' and 'LNP' are synonyms. How can I identify nodes that represent synonyms and merge them in Cytoscape? I searched ...
unikei's user avatar
  • 21
0 votes
1 answer
278 views

How implement updating index by synonyms without closing index?

I need implement search by synonyms, now it possible todo by closing index, update index by synonym filter, open index. The probem is that users can update synonym dictanory in any time, and it should ...
stepan's user avatar
  • 1
4 votes
1 answer
157 views

Why does using PatternSynonyms trigger a non-exhaustive match warning?

I'm following this answer to learn how to pattern match on Sequences. For concreteness, imagine that I'm implementing breadth-first search over a 2-d grid using a Sequence as a queue. Using just ...
thisisrandy's user avatar
  • 3,025
0 votes
1 answer
123 views

How to refactor a Haskell data type with fields into a tagged union of records?

In a large code base, I want to refactor a data type that has constructors with fields into a simple tagged union of records, mainly to better support -Wincomplete-record-updates. It is important ...
Andreas Abel's user avatar
5 votes
0 answers
126 views

Explicit type variable instantiation for pattern synonyms?

Suppose, I have the following code data F a where F :: Typeable a => F a asType :: forall b a. Typeable b => F a -> Maybe (a :~: b, F b) asType e@F{} = case eqT @b @a of Just Refl -> ...
Artem Yu's user avatar
  • 4,482
2 votes
1 answer
318 views

How to explicitly import 'Fn' pattern from Test.QuickCheck?

Haskell's Test.QuickCheck module exports pattern Fn, which I have been using. When I import it with: import Test.QuickCheck it works fine. However, when I import it with: import Test.QuickCheck (Fn) ...
mherzl's user avatar
  • 6,170
2 votes
0 answers
103 views

Generating shingles with synonyms in Elasticsearch

I have a file of alternate spellings for the terms in my index. I want to produce bigrams containing those alternate spellings for particular terms. For example, I have biriyani, biryani, briyani in ...
Yawan Gupta's user avatar
4 votes
1 answer
241 views

Pattern synonyms as overloadable 'smart constructors'

There's a fine tradition of including 'smart constructor' methods in an interface (class): class Collection c a where empty :: c a singleton :: a -> c a -- etc It would be nice to supply ...
AntC's user avatar
  • 2,806
8 votes
1 answer
108 views

Why does my pattern block an error on both sides?

To start off this whole thing I'm working with a pattern synonym defined as follows: {-# Language PatternSynonyms #-} pattern x := y <- x @ y This allows me to run multiple pattern matches across ...
Wheat Wizard's user avatar
  • 4,074
4 votes
1 answer
165 views

Why are recursive pattern synonyms accepted?

This question (from 5 years ago) asks 'Why are all recursive pattern synonyms rejected?' and its example is still rejected. The User Guide says "Pattern synonyms cannot be defined recursively.&...
AntC's user avatar
  • 2,806
3 votes
1 answer
150 views

Can a pattern synonym have a different type signature in each direction, like numeric literals do?

Consider the numeric literal 1. It has a different type depending on whether it's used on the left or right of the equals sign. In f True = 1, 1 has type Num p => p. But in f 1 = True, 1 has type (...
Joseph Sible-Reinstate Monica's user avatar
1 vote
2 answers
151 views

Design options for constructor constraints: GADT compare PatternSynonym Required

(This is a follow-up to this answer, trying to get the q more precise.) Use Case Constructors to build/access a Set datatype. Being a set, the invariant is 'no duplicates'. To implement that I need an ...
AntC's user avatar
  • 2,806
4 votes
1 answer
188 views

Pattern synonyms signature: Required vs Provided constraints

I think I get it with the "unusual form" of constraints. Just checking ... The examples in that section for Provided constraints (the second one) all seem to involve GADTs/existentials ...
AntC's user avatar
  • 2,806
3 votes
1 answer
550 views

Writing a pattern synonym to hide a constructor

Consider the following: module MyModule ( A(FortyTwo), -- Note we don't expose PrivateA B(P) -- Nor PrivateB ) where pattern FortyTwo = A 42 newtype A = PrivateA Int data B = PrivateB Int Int ...
Clinton's user avatar
  • 23.1k
5 votes
1 answer
233 views

No-fun/puzzlement with pattern synonyms as functions

With PatternSynonyms (explicitly bidirectional form), the pattern-to-expr equations in effect form a function but spelled upper-case (providing you end up with an fully saturated data constr of the ...
AntC's user avatar
  • 2,806
0 votes
1 answer
124 views

Identifying synonymous rows of a text column in a dataframe using R

Suppose ABC is a dataframe as given below: ABC <- data.frame(Column1 = c(1.222, 3.445, 5.621, 8.501, 9.302), Column2 = c(654231, 12347, -2365, 90000, 12897), ...
Ray's user avatar
  • 351
0 votes
0 answers
102 views

Patterns and View patterns: am I doing this right

I want to achieve {-# LANGUAGE PatternSynonyms, ViewPatterns #-} pattern Just2 :: (Num a, Eq a) => a -> a -> Maybe (a, a) -- Just2 0 0 ≡ Nothing -- Just2 x y ≡ Just (x, y) I think I've ...
AntC's user avatar
  • 2,806
0 votes
1 answer
300 views

extracting synonyms using wordnet

I am currently working on my thesis and implementing the solution in R language. i have to find synonyms using word-net dictionary library. i get the synonyms against single word but when i try to get ...
Basit Amin's user avatar
7 votes
1 answer
323 views

Writing a COMPLETE pragma for a polymorphic pattern synonym?

I have the following code and I don't know what should feed at ??. Or cannot polymorphic patterns make complete? {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-} module Data.Tuple....
Kazuki Okamoto's user avatar
3 votes
2 answers
149 views

Can I capture values from a pattern synonym?

Assuming a pattern: pattern P :: [Int] pattern P <- a:_ Can I somehow use a in the function f? f :: [Int] -> Int f P = a The code above generates an error of Not in scope: 'a'.
Bartek Banachewicz's user avatar
0 votes
1 answer
1k views

Replacing a word by randomly selected synonyms in a string?

I have found the following code in Python that is doing the same work but it only replaces with manually selected synonym. import nltk from nltk.corpus import wordnet synonyms = [] string="i love ...
Mudassir Awan's user avatar
-1 votes
1 answer
175 views

How to update/save oracle synonyms in database with Python/Django

I am writing a web in Python, I would like to save or update oracle synonyms as select * from synonyms into local database, so the local python program can use those values at regular intervals, I was ...
Elsa's user avatar
  • 626
3 votes
1 answer
352 views

How to find similar noun phrases in NLP?

Is there a way to identify similar noun phrases. Some suggest use pattern-based approaches, for example X as Y expressions: Usain Bolt as Sprint King Liverpool as Reds
Shimak's user avatar
  • 89
1 vote
0 answers
156 views

Pattern synonyms deriving read?

Pattern synonyms provide a shorthand way to express a value; also they can provide an abstract name to avoid a client module breaking into the data decl. Here's a not very useful one, as an example ...
AntC's user avatar
  • 2,806
12 votes
1 answer
1k views

Haskell: "Qualified name in binding position" error with Map.empty

I'm trying to create a pattern synonym for a newtype with an empty map. {-# Language PatternSynonyms #-} import qualified Data.Map as Map newtype StoreEnv = StoreEnv (Map.Map Int String) ...
Tien Ho's user avatar
  • 133
2 votes
1 answer
209 views

Use literal numbers in Fin patterns

On one hand, I can use #_ to construct Fins from literals: open import Data.Fin data I'mFinnish : Set where Mk : Fin 5 → I'mFinnish foo : I'mFinnish foo = Mk (# 3) On the other hand, I can use ...
Cactus's user avatar
  • 27.6k
2 votes
1 answer
551 views

Using ViewPatterns and PatternSynonyms to simply pattern matches

Lets say I have a GADT for a language like so (my actual language is much more complex, about 50 constructors, but this is a simplified example): data Expr t where Add :: Expr t -> Expr t -> ...
Clinton's user avatar
  • 23.1k
5 votes
1 answer
243 views

How can I write this pattern synonym without ambiguous type errors?

Using ViewPatterns and Data.Typeable, I’ve managed to write a function that allows me to write something resembling case analysis on types. Observe: {-# LANGUAGE GADTs, PatternSynonyms, RankNTypes, ...
Alexis King's user avatar
  • 43.8k
7 votes
3 answers
2k views

Haskell pattern matching on vectors

Is it possible to use list style pattern matching on vectors? ie import qualified Data.Vector as V f :: V.Vector a -> a f (x:xs) = x gives an error
matt's user avatar
  • 2,021
3 votes
1 answer
104 views

Manually specifying ismorphisms for unidirectional pattern synonym

There probably isn't a way to do this, but I just wanted to ask just in case. I have a data type that's a simple tuple like this: data Tup a = T a a I have a pattern synonym like this: pattern (:?)...
Justin L.'s user avatar
  • 13.6k
6 votes
1 answer
1k views

How to Pattern Match an Empty Vector in Haskell?

Say I want to implement the length function for lists using pattern matching, then I could do something like this: length' :: (Num b) => [a] -> b length' [] = 0 length' (_:xs) = 1 + length' ...
frmsaul's user avatar
  • 1,366
8 votes
1 answer
153 views

Pattern synonym can't unify types within type-level list

I'm getting an error when trying to define a pattern synonym based on a GADT that has a type-level list. I managed to boil it down to this example: {-# LANGUAGE GADTs #-} {-# LANGUAGE KindSignatures ...
rampion's user avatar
  • 88.9k
1 vote
2 answers
294 views

How would we take the last value of a list using colon notation?

Say we have a list in the parameter and pattern match on its head and tail separately so we use x:xs. This means that the inputs are split into a value x and a list xs. So whatever is before the ...
Qwertford's user avatar
  • 1,189
1 vote
1 answer
2k views

How to pattern match the end of a list?

Say I wanted to remove all zeros at the end of a list: removeEndingZeros :: (Num a, Eq a) => [a] -> [a] removeEndingZeros (xs ++ [0]) = removeEndingZeros xs removeEndingZeros xs = xs ...
Mark Anastos's user avatar
6 votes
1 answer
223 views

Why are all recursive pattern synonyms rejected?

{-# LANGUAGE PatternSynonyms, ViewPatterns #-} data Quun = Foo | Bar | Oink Quun fooey :: Quun -> Bool fooey Foo = True fooey (Oink Yum) = True fooey _ = False pattern Yum <- (fooey -> ...
leftaroundabout's user avatar
4 votes
2 answers
687 views

Haskell - Using a constant in pattern matching

Let's say I have the following code (text in <> is a shorthand, not actually part of the code): data A = <something> defaultA :: A defaultA = <Really complicated expression of type A&...
tohava's user avatar
  • 5,402
3 votes
1 answer
328 views

Constants in Haskell and pattern matching [duplicate]

How is it possible to define a macro constant in Haskell? Especially, I would like the following snippet to run without the second pattern match to be overlapped. someconstant :: Int someconstant = 3 ...
user19018's user avatar
  • 2,479
11 votes
2 answers
736 views

Pattern matching on a private data constructor

I'm writing a simple ADT for grid axis. In my application grid may be either regular (with constant step between coordinates), or irregular (otherwise). Of course, the regular grid is just a special ...
firegurafiku's user avatar
  • 3,116
4 votes
1 answer
350 views

Why can't I pattern match against a ratio in Haskell?

I'm trying to pattern match against a ratio: isValid :: Ratio Int -> Bool isValid (num % den) = ... However, this yields: Parse error in pattern: num % den Interestingly, the Data.Ratio package ...
Ben's user avatar
  • 1,581
10 votes
1 answer
242 views

Combining patterns

Consider the following data type and pattern synonyms: {-# LANGUAGE PatternSynonyms, NamedFieldPuns #-} data Foo = Foo { a :: Int , b :: String , c :: Maybe Bool } pattern Bar a b <...
wrl's user avatar
  • 131
12 votes
2 answers
2k views

Pattern matching Data.Sequence like lists

I am using Data.Sequence instead lists for better performance. With lists we can do the following foo :: [Int] -> Int foo [] m = m foo (x:xs) m = ... How can this be accomplished with Data....
abden003's user avatar
  • 1,335
12 votes
1 answer
389 views

A list whose "Nil" carries a value?

Does some standard Haskell library define a data type like this data ListWithEnd e a = Cons a (ListWithEnd e a) | End e That is a list whose terminating element carries a value ...
Petr's user avatar
  • 63.3k
5 votes
2 answers
367 views

How to handle lots of constants in Haskell?

I’m working on a library allowing a developper to control a Minitel (the french videotex terminal). I have a lot of constant values and I would like to know the best way to manage them with Haskell. ...
zigazou's user avatar
  • 1,755
17 votes
1 answer
833 views

Pattern synonyms lead to unexhaustive pattern matching

I've managed to construct the following "minimal" example that shows my problem. Provided the PatternSynonyms extension is enabled data Vec = Vec Int Int pattern Ve x y = Vec x y f :: (Vec, Vec) -&...
Luka Horvat's user avatar
  • 4,392
3 votes
2 answers
225 views

Haskell type synonym issue

This gives me the following error Not in scope: data constructor Blah Why? I thought that I can use the type synonym everywhere I can use Person data Person = Person { weight :: Int, height :: ...
user361633's user avatar
5 votes
2 answers
2k views

Haskell constructor aliases

Is there a way to have something equivalent to creating "constructor aliases" in Haskell? I'm thinking similar to type aliases where you can give the type a different name but it still behaves in ...
Ben's user avatar
  • 71.3k