Haskell pattern match on type -


is there way of doing in haskell ?

data fruits = apple int | orange int deriving (eq, show)  basket = [apple 2, orange 4]  from_basket t (x:basket) =     case x of         (t i) ->         _ -> from_basket t basket 

now want 'apple' list of fruits ( basket )

from_basket apple basket 

without explicit pattern match

case x of     apple -> ...     orange -> ...     _ -> 

one way define own helper function isapple , filtering:

isapple (apple _) = true isapple _         = false  getapples = filter isapple 

pattern matching tool of choice, don't know whether can simplify further. apart fro dirty template haskell, don't see other way.


Comments