Hibernate Docs(2.2.5.1.一对一)提供了以下示例:
@Entity
public class Customer implements Serializable {
@OneToOne(cascade = CascadeType.ALL)
@JoinColumn(name="passport_fk")
public Passport getPassport() {
...
}
@Entity
public class Passport implements Serializable {
@OneToOne(mappedBy = "passport")
public Customer getOwner() {
...
}
Run Code Online (Sandbox Code Playgroud)
据我了解,Customer有一个一比一的关系Passport,这里Customer是所有者,即负责级联更新Passport.在mappedBy在Passport表明它有一个一对一的关系Customer,但它是不负责级联更新Customer.
Customer有一个外键约束Passport的,以及反之亦然Passport来Customer.
是什么意思@JoinColumn(name="passport_fk")的Customer?如何passport在mappedBy的Passport?它们是表示各自外键的表列吗?
为什么这两种都有相同的类型?
ghci> :k [Int]
[Int] :: *
ghci> :k [Int -> Int]
[Int -> Int] :: *
Run Code Online (Sandbox Code Playgroud)
编辑 @ Gabriel Gonzalez的有用评论.
我不太了解kinds,所以我没有很好的基础来期待上述类型的变化kind.
了解一下Haskell的讨论newtype.
它的签名是如何Pair b a意味着传入的参数必须是一个元组?
ghci> newtype Pair b a = Pair { getPair :: (a, b) }
ghci> let p = Pair (5, 10)
Run Code Online (Sandbox Code Playgroud)
我很困惑如何b a表示一个元组.
I'n看国家单子的put和get:
ghci> :t get
get :: MonadState s m => m s
ghci> :t runState
runState :: State s a -> s -> (a, s)
ghci> runState get [1,2,3]
([1,2,3],[1,2,3])
Run Code Online (Sandbox Code Playgroud)
在get's类型签名:MonadState s m => m s,有怎样[1,2,3]的类型MonadState s m?目前尚不清楚对我有什么的类型s和m是.
另外,您能否详细说明如何使用put?
ghci>:t put put :: MonadState sm => s - > m()
总的来说,似乎我不明白是什么MonadState s m.你能解释一下put和get例子吗?
给出以下类型:
import Data.Set as Set
-- http://json.org/
type Key = String
data Json = JObject Key (Set JValue)
| JArray JArr
deriving Show
data JObj = JObj Key JValue
deriving Show
data JArr = Arr [JValue] deriving Show
data Null = Null deriving Show
data JValue = Num Double
| S String
| B Bool
| J JObj
| Array JArr
| N Null
deriving Show
Run Code Online (Sandbox Code Playgroud)
我JObject Key (Set Value)用一个元素创建了一个:
ghci> JObject "foo" (Set.singleton (B True))
JObject "foo" …Run Code Online (Sandbox Code Playgroud) 纵观国家单子的维基,我试图了解runState和put功能.
据我所知runState,它需要第一个参数State,它有一个"宇宙" s,和一个值,a.它需要宇宙的第二个参数.最后,它返回一个(a, s)地方a是新的价值,s是新的宇宙?
ghci> :t runState
runState :: State s a -> s -> (a, s)
Run Code Online (Sandbox Code Playgroud)
例:
ghci> let s = return "X" :: State Int String
ghci> runState s 100
("X",100)
Run Code Online (Sandbox Code Playgroud)
但是,我不明白put结果:
ghci> runState (put 5) 1
((),5)
Run Code Online (Sandbox Code Playgroud)
既然runState返回了(a, s),为什么是a类型()?
我对上面的尝试解释没有信心.请纠正我,并回答我的问题put.
鉴于Free Monad:
data Free f a = Var a
| Node (f (Free f a))
Run Code Online (Sandbox Code Playgroud)
我试图Eq为它定义一个实例:
instance (Functor f, Eq (f a)) => Eq (Free f a) where
(==) (Var x) (Var y) = x == y
(==) (Node fu1) (Node fu2) = fu1 == fu2
(==) _ _ = False
Run Code Online (Sandbox Code Playgroud)
但是无法编译:
FreeMonad.hs:17:10:
Non type-variable argument in the constraint: Eq (f a)
(Use FlexibleContexts to permit this)
In the context: (Functor f, Eq (f a))
While …Run Code Online (Sandbox Code Playgroud) 根据 scala 规范, scala.Nothing 类型 - 所有类型的按钮。类型“Nothing”存在,但 Nothing 的实例不存在。
这个怎么运作:
def ??? : Nothing = throw new NoImplementedError
def sys.error(message: String): Nothing = throw new RuntimeException()
def sys.exit(status: Int): Nothing = {...}
Run Code Online (Sandbox Code Playgroud)
但实际上,所有提到的方法都返回异常。例外def sys.exit你能否澄清更多关于无类型的信息。任何例子,解释。
谢谢!
Looking at exercise 9.2 from Type-Driven Development with Idris:
data Last : List a -> a -> Type where
LastOne : Last [value] value
LastCons : (prf : Last xs value) -> Last (x :: xs) value
Uninhabited (Last [] value) where
uninhabited LastOne impossible
uninhabited (LastCons _) impossible
notLast : Not (x = value) -> Last [x] value -> Void
notLast prf LastOne impossible
notLast prf (LastCons _) impossible
isLast : DecEq a => (xs : List a) -> …Run Code Online (Sandbox Code Playgroud) 鉴于两个case classes:
case class Foo(x: Int)
case class Bar(x: Int)
Run Code Online (Sandbox Code Playgroud)
用shapeless,我怎么能确定Foo,并Bar具有相同的"形",即Int :: HNil是HList?