虽然这个例子是设计的,但如果忽略数据构造函数,为什么我不能使用通配符模式呢?
module Main where
import Prelude
import Control.Monad.Eff.Console (log)
data Person = Amy { name :: String } | George { name :: String }
--Implementations Options Below
main = log $ personToString $ George { name: "George" }
Run Code Online (Sandbox Code Playgroud)
没有错误
personToString :: Person -> String
personToString (Amy { name: n }) = n
personToString (George { name: n }) = n
Run Code Online (Sandbox Code Playgroud)
错误
personToString :: Person -> String
personToString (_ { name: n }) = n
Run Code Online (Sandbox Code Playgroud)
http://try.purescript.org/?session=a1503b9a-0546-7832-39b0-6321a89ef2e3
Unable to parse module: …Run Code Online (Sandbox Code Playgroud) 这种语法非常有用 - 这是否有理由不起作用?谢谢!
module Foo = {
let bar: string = "bar"
};
let bar = Foo.bar; /* works */
let { bar } = Foo; /* Unbound record field bar */
Run Code Online (Sandbox Code Playgroud)
1)有没有办法输入这个?2)任何人都能够解释这些错误消息?
let identity1: 'a => 'a = [%bs.raw {|
function(value) {
return value
}
|}];
/*
Line 2, 11: The type of this expression, '_a -> '_a, contains type variables that cannot be generalized
*/
let identity2: 'a. 'a => 'a = [%bs.raw {|
function(value) {
return value
}
|}];
/*
Line 8, 11: This definition has type 'a -> 'a which is less general than 'a0. 'a0 -> 'a0
*/
Run Code Online (Sandbox Code Playgroud)
class Test extends StatelessWidget {
Widget build(BuildContext context) {
return UnconstrainedBox(
child: Container(
height: 250.0,
width: 250.0,
decoration:
BoxDecoration(shape: BoxShape.circle, color: Colors.red),
child: Opacity(
opacity: 0.5,
child: Container( // WIDGET IN QUESTION
constraints:
BoxConstraints.expand(width: 50.0, height: 50.0),
color: Colors.yellow))));
}
}
Run Code Online (Sandbox Code Playgroud)
根据容器类文档 ...
如果窗口小部件没有子级且没有对齐方式,但是提供了高度,宽度或约束,则在给定那些约束和父级约束的组合的情况下,容器将尝试尽可能小。
而是,该小部件正在尝试尽可能大(父级大小)而不是50x50。我知道我可以使用UnconstrainedBox,但是我正在寻找这种行为的解释。