Skip to content

Make [n..] etc syntax rebindable

The [foo..], [foo..bar], [foo,bar..] and [foo,bar..baz] sugars do not obey -fno-implicit-prelude.

{-# OPTIONS_GHC -fno-implicit-prelude #-}
module ListSugar where

import Control.Monad
import Prelude hiding (Enum,enumFrom)

class Enum a where 
   enumFrom :: MonadPlus m => a -> m a
instance Enum Int where 
   enumFrom n = return n `mplus` enumFrom (n + 1)

main = print $ ([1..] :: Maybe Int)

ListSugar.hs:9:16:
    Couldn't match expected type `Maybe Int'
           against inferred type `[a]'
    In the expression: [1 .. ]
    In the second argument of `($)', namely `([1 .. ] :: Maybe Int)'
    In the expression: print $ ([1 .. ] :: Maybe Int)

and even with the same signature as the original type, it invokes the version in the Prelude.

Edited by Ian Lynagh -
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information