The OverloadedLists language pragma in GHC 7.8 is quite attractive, so I decided to try it:

{-# LANGUAGE OverloadedLists #-}

import Data.Set (Set)                                                                     
import qualified Data.Set as Set

mySet :: Set Int
mySet = [1,2,3]

And the compiler gives me:

    No instance for (GHC.Exts.IsList (Set Int))
      arising from an overloaded list
    In the expression: [1, 2, 3]
    In an equation for ‘mySet’: mySet = [1, 2, 3]

    No instance for (Num (GHC.Exts.Item (Set Int)))
      arising from the literal ‘1’
    In the expression: 1
    In the expression: [1, 2, 3]
    In an equation for ‘mySet’: mySet = [1, 2, 3]
Failed, modules loaded: none.

Even the example from the release notes doesn't work:

> ['0' .. '9'] :: Set Char

<interactive>:5:1:
    Couldn't match type ‘GHC.Exts.Item (Set Char)’ with ‘Char’
    Expected type: [Char] -> Set Char
      Actual type: [GHC.Exts.Item (Set Char)] -> Set Char
    In the expression: ['0' .. '9'] :: Set Char
    In an equation for ‘it’: it = ['0' .. '9'] :: Set Char

Does anyone know what's going on here?

share|improve this question
1  
It says in the error: No instance for (GHC.Exts.IsList (Set Int)). Data.Set doesn't define an instance for IsList. You can write the instance yourself quite easily, here is the class: hackage.haskell.org/package/base-4.7.0.0/docs/… – user2407038 Apr 25 '14 at 1:36
up vote 7 down vote accepted

There is only a trivial instance defined in the source. You can define your own instance for Data.Set using:

{-# LANGUAGE TypeFamilies #-}

instance IsList (Set a) where
  type Item (Set a) = a
  fromList = Data.Set.fromList
  toList = Data.Set.toList

Note that IsList is only available for GHC >= 7.8.

share|improve this answer
    
That's unfortunate, I had thought those instances were built-in. – Colin Woodbury Apr 25 '14 at 4:06
2  
Also note you need to use the TypeFamilies pragma as well for this to work. – Colin Woodbury Apr 25 '14 at 18:16
2  
Thanks for pointing that out; I've edited the answer accordingly. – crockeea Apr 25 '14 at 21:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.