Skip to content

Commit

Permalink
Fix formatting with newer hindent
Browse files Browse the repository at this point in the history
  • Loading branch information
gibiansky committed Aug 25, 2015
1 parent ad66ac8 commit 62b6c55
Show file tree
Hide file tree
Showing 21 changed files with 653 additions and 414 deletions.
3 changes: 2 additions & 1 deletion Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
13 changes: 6 additions & 7 deletions ghc-parser/Setup.hs
@@ -1,8 +1,7 @@
import Distribution.Simple
import System.Cmd
import Distribution.Simple
import System.Cmd

main = defaultMainWithHooks simpleUserHooks{
preConf = \args confFlags -> do
system "./build-parser.sh"
preConf simpleUserHooks args confFlags
}
main = defaultMainWithHooks
simpleUserHooks { preConf = \args confFlags -> do
system "./build-parser.sh"
preConf simpleUserHooks args confFlags }
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-aeson/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-basic/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-blaze/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-charts/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-diagrams/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-hatex/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-juicypixels/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-magic/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-parsec/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-plot/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-rlangqq/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-static-canvas/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
3 changes: 2 additions & 1 deletion ihaskell-display/ihaskell-widgets/Setup.hs
@@ -1,2 +1,3 @@
import Distribution.Simple
import Distribution.Simple

main = defaultMain
Expand Up @@ -4,14 +4,15 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE GADTs #-}

module IHaskell.Display.Widgets.Common where

import Data.Aeson
import Data.Aeson.Types (emptyObject)
import Data.Text (pack, Text)
import Data.Aeson
import Data.Aeson.Types (emptyObject)
import Data.Text (pack, Text)

import IHaskell.Display (IHaskellWidget)
import IHaskell.Eval.Widgets (widgetSendClose)
import IHaskell.Display (IHaskellWidget)
import IHaskell.Eval.Widgets (widgetSendClose)

import qualified IHaskell.Display.Widgets.Singletons as S

Expand Down Expand Up @@ -91,7 +92,8 @@ pattern SelectedIndex = S.SSelectedIndex
closeWidget :: IHaskellWidget w => w -> IO ()
closeWidget w = widgetSendClose w emptyObject

newtype StrInt = StrInt Integer deriving (Num, Ord, Eq, Enum)
newtype StrInt = StrInt Integer
deriving (Num, Ord, Eq, Enum)

instance ToJSON StrInt where
toJSON (StrInt x) = toJSON . pack $ show x
Expand Down Expand Up @@ -205,7 +207,8 @@ instance ToJSON ImageFormatValue where
toJSON = toJSON . pack . show

-- | Options for selection widgets.
data SelectionOptions = OptionLabels [Text] | OptionDict [(Text, Text)]
data SelectionOptions = OptionLabels [Text]
| OptionDict [(Text, Text)]

-- | Orientation values.
data OrientationValue = HorizontalOrientation
Expand Down
Expand Up @@ -10,18 +10,13 @@
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE PatternSynonyms #-}

module IHaskell.Display.Widgets.Interactive (
interactive,
uncurryHList,
Rec (..),
Argument (..),
) where
module IHaskell.Display.Widgets.Interactive (interactive, uncurryHList, Rec(..), Argument(..)) where

import Data.Text
import Data.Proxy

import Data.Vinyl.Core
import Data.Vinyl.Functor (Identity (..), Const (..))
import Data.Vinyl.Functor (Identity(..), Const(..))
import Data.Vinyl.Derived (HList)
import Data.Vinyl.Lens (type ())
import Data.Vinyl.TypeLevel (RecAll)
Expand All @@ -39,35 +34,49 @@ import IHaskell.Display.Widgets.Int.BoundedInt.IntSlider
import IHaskell.Display.Widgets.Float.BoundedFloat.FloatSlider
import IHaskell.Display.Widgets.Output


data WidgetConf a where
WidgetConf :: (RecAll Attr (WidgetFields (SuitableWidget a)) ToPairs, FromWidget a)
=> WrappedWidget (SuitableWidget a) (SuitableHandler a) (SuitableField a) a
-> WidgetConf a

newtype WrappedConstructor a = WrappedConstructor {
wrappedConstructor :: IO (IPythonWidget (SuitableWidget a))
}

WidgetConf ::
(RecAll Attr (WidgetFields (SuitableWidget a)) ToPairs,
FromWidget a) =>
WrappedWidget (SuitableWidget a) (SuitableHandler a)
(SuitableField a)
a
-> WidgetConf a

newtype WrappedConstructor a =
WrappedConstructor
{ wrappedConstructor :: IO (IPythonWidget (SuitableWidget a)) }


type family WithTypes (ts :: [*]) (r :: *) :: * where
WithTypes '[] r = r
WithTypes (x ': xs) r = (x -> WithTypes xs r)
WithTypes '[] r = r
WithTypes (x ': xs) r = (x -> WithTypes xs r)

uncurryHList :: WithTypes ts r -> HList ts -> r
uncurryHList f RNil = f
uncurryHList f (Identity x :& xs) = uncurryHList (f x) xs

-- Consistent type variables are required to make things play nicely with vinyl

data Constructor a where
Constructor :: RecAll Attr (WidgetFields (SuitableWidget a)) ToPairs
=> IO (IPythonWidget (SuitableWidget a)) -> Constructor a
Constructor ::
RecAll Attr (WidgetFields (SuitableWidget a)) ToPairs =>
IO (IPythonWidget (SuitableWidget a)) -> Constructor a

newtype Getter a = Getter (IPythonWidget (SuitableWidget a) -> IO a)

newtype EventSetter a = EventSetter (IPythonWidget (SuitableWidget a) -> IO () -> IO ())

newtype Initializer a = Initializer (IPythonWidget (SuitableWidget a) -> Argument a -> IO ())

newtype Trigger a = Trigger (IPythonWidget (SuitableWidget a) -> IO ())


data RequiredWidget a where
RequiredWidget :: RecAll Attr (WidgetFields (SuitableWidget a)) ToPairs
=> IPythonWidget (SuitableWidget a)
-> RequiredWidget a
RequiredWidget ::
RecAll Attr (WidgetFields (SuitableWidget a)) ToPairs =>
IPythonWidget (SuitableWidget a) -> RequiredWidget a

-- Zipping vinyl records in various ways
applyGetters :: Rec Getter ts -> Rec RequiredWidget ts -> IO (HList ts)
Expand Down Expand Up @@ -108,8 +117,9 @@ createWidget :: Constructor a -> IO (RequiredWidget a)
createWidget (Constructor con) = fmap RequiredWidget con

mkChildren :: Rec RequiredWidget a -> [ChildWidget]
mkChildren widgets = let childRecord = rmap (\(RequiredWidget w) -> Const (ChildWidget w)) widgets
in recordToList childRecord
mkChildren widgets =
let childRecord = rmap (\(RequiredWidget w) -> Const (ChildWidget w)) widgets
in recordToList childRecord

class MakeConfs (ts :: [*]) where
mkConfs :: proxy ts -> Rec WidgetConf ts
Expand All @@ -122,13 +132,13 @@ instance (FromWidget t, MakeConfs ts) => MakeConfs (t ': ts) where

interactive :: (IHaskellDisplay r, MakeConfs ts)
=> (HList ts -> r) -> Rec Argument ts -> IO FlexBox
interactive func = let confs = mkConfs Proxy
in liftToWidgets func confs
interactive func =
let confs = mkConfs Proxy
in liftToWidgets func confs

-- | Transform a function (HList ts -> r) to one which:
-- 1) Uses widgets to accept the arguments
-- 2) Accepts initial values for the arguments
-- 3) Creates a compound FlexBox widget with an embedded OutputWidget for display
-- | Transform a function (HList ts -> r) to one which: 1) Uses widgets to accept the arguments 2)
-- Accepts initial values for the arguments 3) Creates a compound FlexBox widget with an embedded
-- OutputWidget for display
liftToWidgets :: IHaskellDisplay r
=> (HList ts -> r) -> Rec WidgetConf ts -> Rec Argument ts -> IO FlexBox
liftToWidgets func rc initvals = do
Expand All @@ -154,7 +164,6 @@ liftToWidgets func rc initvals = do
-- Set initial values for all widgets
setInitialValues initializers widgets initvals
-- applyValueSetters valueSetters widgets $ getList defvals

setField out Width 500
setField bx Orientation VerticalOrientation

Expand All @@ -164,10 +173,14 @@ liftToWidgets func rc initvals = do

return bx


data WrappedWidget w h f a where
WrappedWidget :: (FieldType h ~ IO (), FieldType f ~ a, h WidgetFields w, f WidgetFields w,
ToPairs (Attr h), IHaskellWidget (IPythonWidget w), ToPairs (Attr f))
=> IO (IPythonWidget w) -> S.SField h -> S.SField f -> WrappedWidget w h f a
WrappedWidget ::
(FieldType h ~ IO (), FieldType f ~ a, h WidgetFields w,
f WidgetFields w, ToPairs (Attr h),
IHaskellWidget (IPythonWidget w), ToPairs (Attr f)) =>
IO (IPythonWidget w) ->
S.SField h -> S.SField f -> WrappedWidget w h f a

construct :: WrappedWidget w h f a -> IO (IPythonWidget w)
construct (WrappedWidget cons _ _) = cons
Expand Down Expand Up @@ -212,7 +225,8 @@ instance FromWidget Integer where
type SuitableWidget Integer = IntSliderType
type SuitableHandler Integer = S.ChangeHandler
type SuitableField Integer = S.IntValue
data Argument Integer = IntVal Integer | IntRange (Integer, Integer, Integer)
data Argument Integer = IntVal Integer
| IntRange (Integer, Integer, Integer)
wrapped = WrappedWidget mkIntSlider ChangeHandler IntValue
initializer w (IntVal int) = setField w IntValue int
initializer w (IntRange (v, l, u)) = do
Expand All @@ -224,7 +238,8 @@ instance FromWidget Double where
type SuitableWidget Double = FloatSliderType
type SuitableHandler Double = S.ChangeHandler
type SuitableField Double = S.FloatValue
data Argument Double = FloatVal Double | FloatRange (Double, Double, Double)
data Argument Double = FloatVal Double
| FloatRange (Double, Double, Double)
wrapped = WrappedWidget mkFloatSlider ChangeHandler FloatValue
initializer w (FloatVal d) = setField w FloatValue d
initializer w (FloatRange (v, l, u)) = do
Expand Down
Expand Up @@ -5,12 +5,15 @@
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE QuasiQuotes #-}

module IHaskell.Display.Widgets.Singletons where

import Data.Singletons.TH
import Data.Singletons.TH

-- Widget properties
singletons [d|
singletons
[d|

data Field = ViewModule
| ViewName
| MsgThrottle
Expand Down Expand Up @@ -83,4 +86,4 @@ singletons [d|
| Titles
| SelectedIndex
deriving (Eq, Ord, Show)
|]
|]

0 comments on commit 62b6c55

Please sign in to comment.