KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
I know this is code is a bit silly, but can someone explain why this isList [42] returns True whereas isList2 [42] prints False , and how to prevent this? I'd like to get better understanding of some of the more obscure GHC type extensions, and I thought this would be an interesting example to figure out. {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE OverlappingInstances #-} {-# LANGUAGE IncoherentInstances #-} class IsList a where isList :: a -> Bool instance IsList a where isList x = False instance IsList [a] where isList x = True isList2 = isList main = print (isList 42) >> print (isList2 42) >> print (isList [42]) >> print (isList2 [42])
Tags (comma-separated)
Save Edits
Cancel