int-index / ether

Monad Transformers and Classes
https://int-index.github.io/ether/
BSD 3-Clause "New" or "Revised" License
78 stars 7 forks source link

Get rid of `Proxy#` #27

Closed int-index closed 7 years ago

int-index commented 7 years ago

Can be replaced with TypeApplications and AllowAmbiguousTypes:

{-# LANGUAGE TypeFamilies, RankNTypes, TypeApplications, AllowAmbiguousTypes #-}

class Foo a where
  foo :: forall a' . (a ~ a') => Int

data Bar

instance Foo Bar where
  foo = 42

answer :: Int
answer = foo @Bar
AaronFriel commented 7 years ago

Since you're using TypeApplications which requires GHC >= 8.0.1, why not go all the way and remove the empty data declarations?

{-# LANGUAGE AllowAmbiguousTypes   #-}
{-# LANGUAGE DataKinds             #-}
{-# LANGUAGE FlexibleInstances     #-}
{-# LANGUAGE TypeApplications      #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE KindSignatures        #-}

import GHC.TypeLits
import Numeric (showIntAtBase)
import Data.Char (intToDigit, chr)

class Foo (a :: Symbol) r where
  foo :: r

instance Foo "Bar" Int where
  foo = 42

instance Foo "Baz" String where
  foo = showIntAtBase 13 intToDigit (6*9) ""

instance Foo "Qux" Char where
  foo = chr (foo @"Bar")

answer :: Int
answer = foo @"Bar"

thisWasntIt :: String
thisWasntIt = foo @"Baz"

orWasAdamsBeingCheeky :: Char
orWasAdamsBeingCheeky = foo @"Qux"
int-index commented 7 years ago

You can use Symbol-kinded labels since Ether supports poly-kinds. But there's no way I'm declaring this as the official way to use the lib. I have argued against Symbol labels on multiple occasions:

  1. https://www.reddit.com/r/haskell/comments/4ezl8y/monaderror_help/d25g15q/?context=3
  2. https://github.com/ghc-proposals/ghc-proposals/pull/6#issuecomment-244714004