polymorphism

Prevent Cast Between Two Interfaces

本秂侑毒 提交于 2021-02-10 15:40:19
问题 I have an internal class which contains implementation details, including properties, which should not be publicly accessible. I have to pass this class to public callers, and allow them to pass it around, store it, serialize it, or do basically whatever they want with it. The class can be accessed publicly in two different ways. These ways are exposed as two public interfaces. I would like to prevent the user from casting between the two public interfaces. Here is some code to demonstrate

Prevent Cast Between Two Interfaces

孤者浪人 提交于 2021-02-10 15:40:02
问题 I have an internal class which contains implementation details, including properties, which should not be publicly accessible. I have to pass this class to public callers, and allow them to pass it around, store it, serialize it, or do basically whatever they want with it. The class can be accessed publicly in two different ways. These ways are exposed as two public interfaces. I would like to prevent the user from casting between the two public interfaces. Here is some code to demonstrate

System.Array [] not compatible with float [] [] in F#

好久不见. 提交于 2021-02-10 14:26:52
问题 I need to call a function that takes System.Array [] as one parameter in F#. (The function is in a library). I need to pass an argument of type float [] [] [] but the compiler refuses to compile. To replicate the problem, I wrote the following code let x : float [] [] = Array.init 2 (fun x -> Array.zeroCreate 3) x :> System.Array;; // This is OK val x : float [] [] = [|[|0.0; 0.0; 0.0|]; [|0.0; 0.0; 0.0|]|] > x :> System.Array [];; //Error x :> System.Array [];; ^^^^^^^^^^^^^^^^^^^^ stdin(14

System.Array [] not compatible with float [] [] in F#

血红的双手。 提交于 2021-02-10 14:24:31
问题 I need to call a function that takes System.Array [] as one parameter in F#. (The function is in a library). I need to pass an argument of type float [] [] [] but the compiler refuses to compile. To replicate the problem, I wrote the following code let x : float [] [] = Array.init 2 (fun x -> Array.zeroCreate 3) x :> System.Array;; // This is OK val x : float [] [] = [|[|0.0; 0.0; 0.0|]; [|0.0; 0.0; 0.0|]|] > x :> System.Array [];; //Error x :> System.Array [];; ^^^^^^^^^^^^^^^^^^^^ stdin(14

How to compose polymorphic functions in Haskell? [duplicate]

半世苍凉 提交于 2021-02-08 11:29:40
问题 This question already has an answer here : What is the monomorphism restriction? (1 answer) Closed last month . I have the following file: module SimpleComposition where class Domain a where f :: a -> a g :: a -> a h = f . g When trying to loading it in ghci, I get the error src\play.hs:7:5: error: * No instance for (Domain c0) arising from a use of `f' * In the first argument of `(.)', namely `f' In the expression: f . g In an equation for `h': h = f . g I believe the problem is that the

How to compose polymorphic functions in Haskell? [duplicate]

◇◆丶佛笑我妖孽 提交于 2021-02-08 11:29:18
问题 This question already has an answer here : What is the monomorphism restriction? (1 answer) Closed last month . I have the following file: module SimpleComposition where class Domain a where f :: a -> a g :: a -> a h = f . g When trying to loading it in ghci, I get the error src\play.hs:7:5: error: * No instance for (Domain c0) arising from a use of `f' * In the first argument of `(.)', namely `f' In the expression: f . g In an equation for `h': h = f . g I believe the problem is that the

What is delegation in julia?

纵然是瞬间 提交于 2021-02-08 11:12:31
问题 I see occational references to delegation, or the delegation design pattern in Julia. What is this? E.g. I see it mentioned in This file in DataStructures.jl 回答1: This is a form of polymorphism via composition (rather than inheritance) Say one has a wrapper type, wrapping some instance of a concrete subtype of AbstractT where the wrapper itself is intended to be a subtype of AbstractT (Not nesc always true, but in general). To add all the methods one exacts such a subtype of AbstractT to have

What is delegation in julia?

蓝咒 提交于 2021-02-08 11:11:17
问题 I see occational references to delegation, or the delegation design pattern in Julia. What is this? E.g. I see it mentioned in This file in DataStructures.jl 回答1: This is a form of polymorphism via composition (rather than inheritance) Say one has a wrapper type, wrapping some instance of a concrete subtype of AbstractT where the wrapper itself is intended to be a subtype of AbstractT (Not nesc always true, but in general). To add all the methods one exacts such a subtype of AbstractT to have

Fixing type variables in locale extensions

≡放荡痞女 提交于 2021-02-07 20:14:36
问题 Given this code locale A = fixes foo :: "'a" locale B = A + fixes bar :: "'a × 'a" locale C' = A + fixes baz :: "'a" begin sublocale B foo "(foo, baz)". end I get Type unification failed Failed to meet type constraint: Term: (foo, baz) :: 'b × 'a Type: 'b × 'b so it seems that Isabelle does not understand that baz and foo should be of the same type. Is there a way to fix this? 回答1: The problem is with your declaration of locales B and C . The declaration for B is equivalent to the following

Fixing type variables in locale extensions

北战南征 提交于 2021-02-07 20:09:55
问题 Given this code locale A = fixes foo :: "'a" locale B = A + fixes bar :: "'a × 'a" locale C' = A + fixes baz :: "'a" begin sublocale B foo "(foo, baz)". end I get Type unification failed Failed to meet type constraint: Term: (foo, baz) :: 'b × 'a Type: 'b × 'b so it seems that Isabelle does not understand that baz and foo should be of the same type. Is there a way to fix this? 回答1: The problem is with your declaration of locales B and C . The declaration for B is equivalent to the following