我正在尝试编写代码以从元组链中删除空元组.编译器拒绝该程序:
码:
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FunctionalDependencies #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeOperators #-}
infixr 9 :*
data a :* b = a :* !b
deriving (Show, Eq, Ord)
class Flatten a b | a -> b where
flatten :: a -> b
instance Flatten a a where
flatten = id
instance Flatten a b => Flatten (() :* a) b where
flatten (() :* y) = flatten …Run Code Online (Sandbox Code Playgroud) 我可以用下面的代码告诉函数的参数数量
{-#Language MultiParamTypeClasses#-}
{-#Language FunctionalDependencies#-}
{-#Language UndecidableInstances#-}
data Zero
data Succ a
class Number a
instance Number Zero
instance (Number a) => Number (Succ a)
class NotFunction a
instance NotFunction Int
instance NotFunction Float
instance NotFunction (IO a)
class (Number n) => FunctionLevel f n | f -> n where
functionLevel :: f -> n
instance FunctionLevel Int Zero where
functionLevel = undefined
instance FunctionLevel Float Zero where
functionLevel = undefined
instance FunctionLevel (IO a) Zero where
functionLevel = undefined …Run Code Online (Sandbox Code Playgroud) 他们中的任何一个都暗示另一个吗?
我的逻辑是,如果保留所有依赖项,则不会丢失信息,同样,如果分解是无损的,则一定不会违反功能依赖项。
所以本质上,依赖保留是一种确保您的分解无损的方法。
我很难接受/拒绝它。那么这两者是相互保证的,还是有一种情况可以在没有另一个的情况下实现?
database-design decomposition database-normalization functional-dependencies
我对上一篇文章感到有些困惑,所以我找到了一个很好的例子,应该清理一下. 
hireDate&carReg是主要关键.所以我的问题是任何人都可以找到除我下面确定的任何额外的功能依赖....修改也欢迎:
fd1 carReg -> make, model, outletNo, outletLoc
fd2 custNo -> custName
fd3 outletNo -> outletLoc
fd4 model -> make (only if we assume a model name is unique to a make)
fd5 carReg, hireDate -> make, model, custNo, custName, outletNo, outletLoc
Run Code Online (Sandbox Code Playgroud)
我不确定以上是否正确,我相信还有更多.请有人帮助我最终了解这些该死的FD!
编辑:基于catcall的答案....我的问题是:custName - > custNo如何成为有效的FD?对于上述关系,当然,客户名称只映射到一个客户编号,但凭直觉,我们知道可以将多个J SMith添加到表中.如果是这种情况,则此FD无效,因为它形成1 ..*关系.我们真的可以说custName - > custNo知道这个事实吗?我们只是将FD基于样本数据吗?或者我们是否考虑了可以添加的可能值?
database database-design relational-database functional-dependencies
什么时候BCNF分解不能保留功能依赖...我试图想出这个说R =(V,W,X,Y,Z)
relational-database database-normalization functional-dependencies
以下是GHC的可能性(精神上)吗?
-- Syntax error: parse error on input `a'
class Foo a b c | (a, b) -> c where
foo :: a -> b -> c
Run Code Online (Sandbox Code Playgroud)
我有什么替代品?
我正在使用Haskell的FunctionalDependencies-Extension以及MultiParamTypeClasses.我定义了以下内容:
class Add a b c | a b -> c where
(~+) :: a -> b -> c
(~-) :: a -> b -> c
neg :: a -> a
zero :: a
Run Code Online (Sandbox Code Playgroud)
哪个工作正常(我尝试过Int和Double的实例,最终目标是能够在没有显式转换的情况下添加Int和Doubles).
当我尝试为neg或(〜 - )定义默认实现时,如下所示:
class Add ...
...
neg n = zero ~- n
Run Code Online (Sandbox Code Playgroud)
GHCi(7.0.4)告诉我以下内容:
Ambiguous type variables `a0', `b0', `c0' in the constraint:
(Add a0 b0 c0) arising from a use of `zero'
Probable fix: add a type signature that fixes these type variable(s)
In …Run Code Online (Sandbox Code Playgroud) 我正在开发一个用于运行人工生命实验的框架,我正在尝试使用类型系列而不是函数依赖项.类型族似乎是Haskellers中的首选方法,但我遇到了一种功能依赖似乎更合适的情况.我错过了一招吗?这是使用类型系列的设计.(此代码编译正常.)
{-# LANGUAGE TypeFamilies, FlexibleContexts #-}
import Control.Monad.State (StateT)
class Agent a where
agentId :: a -> String
liveALittle :: Universe u => a -> StateT u IO a
-- plus other functions
class Universe u where
type MyAgent u :: *
withAgent :: (MyAgent u -> StateT u IO (MyAgent u)) ->
String -> StateT u IO ()
-- plus other functions
data SimpleUniverse = SimpleUniverse
{
mainDir :: FilePath
-- plus other fields
}
defaultWithAgent :: (MyAgent u …Run Code Online (Sandbox Code Playgroud) 我想表达我有3个相关的类型类.
我有两个文件.第一:
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
module ModA where
class Class a b c | a -> b, b -> c where
getB :: a -> b
getC :: b -> c
Run Code Online (Sandbox Code Playgroud)
第二:
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
module B where
import qualified ModA
data A = A {f1::String}
data B = B {f2::String}
data C = C {f3::String}
instance ModA.Class A B C where
getB a = B "hey"
getC a = C "ho"
getABForMe = ModA.getB (A …Run Code Online (Sandbox Code Playgroud) 定义:
type family (xs :: [*]) ++ (ys :: [*]) where
'[] ++ ys = ys
(x ': xs) ++ ys = x ': (xs ++ ys)
Run Code Online (Sandbox Code Playgroud)
我有一个GADT,有点像
data Foo :: [*] -> * -> * where
Foo0 :: a -> Foo '[] a
Foo1 :: Foo '[a] a
Foo2 :: Foo vs a -> Foo us a -> Foo (vs ++ us) a
Run Code Online (Sandbox Code Playgroud)
我想做点什么
test :: Foo '[] Int -> Int
test (Foo0 x) = x
test (Foo2 x …Run Code Online (Sandbox Code Playgroud)