Skip to content

Instantly share code, notes, and snippets.

@JBetz
Last active October 9, 2018 14:26
Show Gist options
  • Save JBetz/f167c4fa15d77d9159f5de9d0ab7ecc5 to your computer and use it in GitHub Desktop.
Save JBetz/f167c4fa15d77d9159f5de9d0ab7ecc5 to your computer and use it in GitHub Desktop.
constrained type won't unify
type ProjectColumnFilter =
{ prop :: forall label a r'. IsSymbol label => Show a => Cons label a r' Types.ProjectRow => SProxy label
, propFilter :: PropertyFilter
}
filterProjects :: Pattern -> Array ProjectColumnFilter -> Array Types.Project -> Array Types.Project
filterProjects pattern columnFilters projects =
Array.filter (\proj -> matchesPattern proj && matchesFilters proj) projects
where
matches pat val = contains pat (toLower val)
matchesPattern proj = matches pattern (show proj.code) || matches pattern proj.name
matchesFilters proj = and $ (\{prop, propFilter} ->
let propValue = show $ Record.get prop proj
in case propFilter of
StringPropertyFilter str ->
matches (Pattern str) propValue
RangePropertyFilter start end ->
readFloat propValue >= start && readFloat propValue <= end
SelectionPropertyFilter str ->
propValue == str
) <$> columnFilters
{-
error is on the last line, on `columnFilters`:
Could not match constrained type
IsSymbol label3 => Show a4 => Cons label3 a4 r'5
( id :: ProjectId, ... )
=> SProxy label3
with type
SProxy t1
while trying to match type IsSymbol label3 => Show a4 => Cons label3 a4 r'5
( id :: ProjectId, ... )
=> SProxy label3
with type SProxy t1
while checking that expression columnFilters
has type t0
{ propFilter :: PropertyFilter
, prop :: SProxy t1
| t2
}
in value declaration filterProjects
where r'5 is a rigid type variable
a4 is a rigid type variable
label3 is a rigid type variable
t0 is an unknown type
t2 is an unknown type
t1 is an unknown type
-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment