9

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?

Colin Woodbury
  • 1,799
  • 2
  • 15
  • 25
  • 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: http://hackage.haskell.org/package/base-4.7.0.0/docs/GHC-Exts.html#g:14 – user2407038 Apr 25 '14 at 01:36

1 Answers1

8

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.

crockeea
  • 21,651
  • 10
  • 48
  • 101