Ticket #1776 (closed bug: fixed)

Opened 6 years ago

Last modified 5 years ago

type families : couldn't match type "Elem a" against type "Elem a"

Reported by: guest Owned by: chak
Priority: normal Milestone:
Component: Compiler Version: 6.8
Keywords: Cc: aslatter@…
Operating System: Unknown/Multiple Architecture: Unknown/Multiple
Type of failure: Difficulty: Unknown
Test Case: Blocked By:
Blocking: Related Tickets:

Description

I received the error

GHCi, version 6.8.0.20071012: http://www.haskell.org/ghc/  :? for help
Loading package base ... linking ... done.
[1 of 1] Compiling Test             ( Test.hs, interpreted )

Test.hs:17:27:
    Couldn't match expected type `Elem a'
           against inferred type `Elem a'
      Expected type: Elem a -> Maybe (Elem a) -> Maybe (Elem a)
      Inferred type: Elem a -> Maybe (Elem a) -> Maybe (Elem a)
    In the first argument of `foldr', namely `mf'
    In the second argument of `fromMaybe', namely
        `(foldr mf Nothing xs)'
Failed, modules loaded: none.

when running the following module in GHCi:

{-# LANGUAGE TypeFamilies #-}

module Test where

import qualified Prelude as P
import Prelude hiding (foldr, foldr1)

import Data.Maybe

type family Elem a

class Foldable a where
    foldr :: (Elem a -> b -> b) -> b -> a -> b

    foldr1 :: (Elem a -> Elem a -> Elem a) -> a -> Elem a
    foldr1 f xs = fromMaybe (error "foldr1: empty structure")
                    (foldr mf Nothing xs)
       where mf x Nothing  = Just x
             mf x (Just y) = Just (f x y)

Change History

Changed 6 years ago by chak

  • owner set to chak

Changed 6 years ago by chak

  • status changed from new to closed
  • resolution set to fixed

Changed 5 years ago by simonmar

  • architecture changed from Unknown to Unknown/Multiple

Changed 5 years ago by simonmar

  • os changed from Unknown to Unknown/Multiple
Note: See TracTickets for help on using tickets.