Skip to content

Instantly share code, notes, and snippets.

@nushio3
Last active August 29, 2015 14:22
Show Gist options
  • Save nushio3/25b52e6f6365d777bbcd to your computer and use it in GitHub Desktop.
Save nushio3/25b52e6f6365d777bbcd to your computer and use it in GitHub Desktop.
uom-plugin difference
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fplugin Data.UnitsOfMeasure.Plugin #-}
module Examples where
import Data.UnitsOfMeasure
import Data.UnitsOfMeasure.Convert
import Data.UnitsOfMeasure.Show
[u| kg |]
myMass = [u| 65.2 kg |]
(7.10.1)nushio@nuwheezy:uom-plugin$ runhaskell Main.hs
[u| 65.2 kg |]
(7.10.1)nushio@nuwheezy:uom-plugin$ ghci Main.hs
GHCi, version 7.10.1: http://www.haskell.org/ghc/ :? for help
[1 of 2] Compiling Examples ( Examples.hs, interpreted )
[2 of 2] Compiling Main ( Main.hs, interpreted )
Ok, modules loaded: Examples, Main.
> main
[u| 65.2 kg |]
> print myMass
<interactive>:3:1:
No instance for (Data.UnitsOfMeasure.Singleton.KnownUnit
(Unpack (Base "kg")))
arising from a use of ‘print’
In the expression: print myMass
In an equation for ‘it’: it = print myMass
> :seti -fplugin Data.UnitsOfMeasure.Plugin
> print myMass
[u| 65.2 kg |]
>
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE QuasiQuotes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE UndecidableInstances #-}
{-# OPTIONS_GHC -fplugin Data.UnitsOfMeasure.Plugin #-}
import Data.UnitsOfMeasure
import Data.UnitsOfMeasure.Convert
import Data.UnitsOfMeasure.Show
import Examples
main :: IO ()
main = print myMass
@nushio3
Copy link
Author

nushio3 commented Jun 5, 2015

I wonder why the results of evaluating main and print myMass differ, given that main = print myMass .

@nushio3
Copy link
Author

nushio3 commented Jun 5, 2015

Solution: to activate the type checker plugin in the GHCi. :seti -fplugin Data.UnitsOfMeasure.Plugin . As we can see, when we load a .hs file to GHCi, the plagmas such as type checker plugins and LANGUAGE pragrmas are not activated.

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