I was wondering if ImplicitParams could be emulated via withDict from GHC.Base
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE DataKinds #-}
import GHC.Base (withDict)
class LocalVar str val | str -> val where
local :: val
data LocalDict str val where
LocalDict :: LocalVar str val => LocalDict str val
mkLocalDict :: forall str val. val -> LocalDict str val
mkLocalDict val = withDict @(LocalVar str val) val LocalDict
pattern LocalBind :: forall str val. LocalDict str val -> val
pattern LocalBind dict <- (mkLocalDict @str @val -> dict)
where
LocalBind (LocalDict :: LocalDict str val) = local @str @val
{-# COMPLETE LocalBind #-}
main = do
LocalBind @"inpt" LocalDict <- getLine
putStrLn (local @"inpt")
This gives me:
bus error runhaskell
and
segfault runhaskell
or just doesn’t output anything. Is withDict inherently unsafe or am I doing something wrong?