Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Overloaded Strings Example
{-# LANGUAGE OverloadedStrings #-}
import GHC.Exts ( IsString(..) )
data Foo = A | B | Other String deriving Show
instance IsString Foo where
fromString "A" = A
fromString "B" = B
fromString xs = Other xs
tests :: [ Foo ]
tests = [ "A", "B", "Testing" ]
main :: IO ()
main = mapM_ print tests
@afonsomatos

This comment has been minimized.

Copy link

@afonsomatos afonsomatos commented Sep 8, 2015

Thank you for the example, simple and self-explanatory.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment