So I was playing around with defining a TrieSet datatype (even though I know I don't need to):
module Temp where
import Data.Map
data TrieSet a = Nonterminal (Data.Map a (TrieSet a)) | Terminal (Data.Map a (TrieSet a))
insert :: Ord a => [a] -> TrieSet a -> TrieSet a
insert [] (_ m) = Terminal m
insert (a:as) (c m) = c $ insertWith (insert as . flip const) a (insert as $ Nonterminal empty) m
When I got an error I've never seen before:
% ghc -c Temp.hs
Temp.hs:8:11: Parse error in pattern
So it seemed like GHC doesn't like matching multiple unary constructors with the same pattern. I did another test to make sure that was the problem:
module Temp2 where
extract :: Either String String -> String
extract (_ s) = s
Which seemed to confirm my suspicion:
% ghc -c Temp2.hs
Temp2.hs:4:9: Parse error in pattern
So my question is (in multiple parts):
f (_ n) = n
. What should be its type? The type-system of Haskell has no way to describe the arity of a type's constructors, so a function like f
could not exist.If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With