shunkichi.sato
@shunkichi.sato has joined the channel
sNatToNat' :: Sing n -> Sing (ConvertNat n) sNat'ToNat :: Sing (ConvertNat n) -> Sing n
readCSV :: WrapForall Csv.FromField Vector xs => FilePath -> IO (RecordOf Vector xs) readCSV filepath = do csvBs <- BL.readFile filepath case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of Left reason -> error reason Right vs -> undefined
....hs:36:82: error: • Expected kind '[membership-0:Type.Membership.Internal.Assoc k0 *]', but 'xs' has kind '[*]' • In the second argument of 'RecordOf', namely 'xs' In the first argument of 'IO', namely '(RecordOf Vector xs)' In the type signature: readCSV :: WrapForall Csv.FromField Vector xs => FilePath -> IO (RecordOf Vector xs) | 36 | readCSV :: WrapForall Csv.FromField Vector xs => FilePath -> IO (RecordOf Vector xs) |
{-# LANGUAGE PolyKinds #-}
WrapForall Csv.FromField Vector
がxsの種を [*]
に固定する原因となっています。 Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs
としてはどうでしょう....hs:30:125: error: • Expected kind '[membership-0:Type.Membership.Internal.Assoc * *]', but 'xs' has kind '[membership-0:Type.Membership.Internal.Assoc ghc-prim-0.5.3:GHC.Types.Symbol *]' • In the first argument of 'DataFrame', namely 'xs' In the first argument of 'IO', namely '(DataFrame xs)' In the type signature: readCSV :: Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs => FilePath -> IO (DataFrame xs)
readCSV :: Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs => FilePath -> IO (RecordOf Vector xs) readCSV filepath = do csvBs <- BL.readFile filepath case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of Left reason -> error reason Right vs -> undefined
...hs:52:10: error: • Could not deduce (Forall (Instance1 Csv.FromField (Field Identity)) xs1) arising from a use of 'Csv.decode' from the context: Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs bound by the type signature for: readCSV :: forall (xs :: [membership-0:Type.Membership.Internal.Assoc ghc-prim-0.5.3:GHC.Types.Symbol *]). Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs => FilePath -> IO (RecordOf Vector xs) at src/Data/Frame/Reader.hs:49:1-115 • In the expression: Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) In a stmt of a 'do' block: case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of Left reason -> error reason Right vs -> undefined In the expression: do csvBs <- BL.readFile filepath case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of Left reason -> error reason Right vs -> undefined | 52 | case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} module Data.Frame.Reader where import qualified Data.ByteString.Lazy as BL import qualified Data.Csv as Csv import Data.Extensible import Data.Vector (Vector) readCSV :: forall xs. Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs => FilePath -> IO (RecordOf Vector xs) readCSV filepath = do csvBs <- BL.readFile filepath case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of Left reason -> error reason Right vs -> undefined
.hs:19:10: error: • Could not deduce (Forall (Instance1 Csv.FromField (Field Identity)) xs) arising from a use of 'Csv.decode' from the context: Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs bound by the type signature for: readCSV :: forall (xs :: [Assoc ghc-prim-0.5.3:GHC.Types.Symbol *]). Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Vector)) xs => FilePath -> IO (RecordOf Vector xs) at src/Data/Frame/Reader.hs:16:1-126 • In the expression: Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) In a stmt of a 'do' block: case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of Left reason -> error reason Right vs -> undefined In the expression: do csvBs <- BL.readFile filepath case Csv.decode Csv.HasHeader csvBs :: Either String (Vector (Record xs)) of Left reason -> error reason Right vs -> undefined
readCSV :: forall xs. Forall (KeyValue KnownSymbol (Instance1 Csv.FromField Identity)) xs => FilePath -> IO (RecordOf Vector xs) readCSV filepath = do csvBs <- BL.readFile filepath case Csv.decodeByName csvBs :: Either String (Csv.Header, Vector (Record xs)) of Left reason -> error reason Right vs -> undefined
fact3 :: Int -> Integer fact3 = (map fact' [0..] !!) where fact' 0 = 1 fact' n = fromIntegral n * fact' (n-1)
fact3
はなんで CAF なんでしょう? map
は定数でもなければコンビネーターでもない変数なような……fact3
が CAF であることもありますが,一番の要因として, Core では関数適用の引数は let を通して変数に束縛されることになるので,実際にはこのプログラムはfact3 = (!!) fact3' where fact3' = map fact' l l = [0..] fact' 0 = 1 fact' n = ...
fact3 = \x -> (!!) fact3' x
という形になっていました)fact3
を定義したときに、というべきか。whereで定義しているローカル関数fibはfib_memにぶら下がっているのに対してfib_mem_argの方はfib_mem_arg nに対してローカル関数fibがぶらさがっている.なるほどー これしっくりきました