在GHCi中工作>但不是在加载时?(Works in GHCi> but not when loaded?)
我无法弄清楚为什么我得到两个不同的结果,但我确定它与
IO
,我开始讨厌!例如:
ghci> x <- readFile "foo.txt" ghci> let y = read x :: [Int] ghci> :t y y :: [Int]
现在,当我创建该文件并执行相同的操作时,它会以
IO [Int]
?
foo.txt
是一个仅包含此内容的txt文件:12345
有人可以向我解释一下吗? 因为我要抢购它!
感谢您的任何见解!
I cant figure out why I get two different results but I'm sure it has to do with
IO
, which I am beginning to hate!For example:
ghci> x <- readFile "foo.txt" ghci> let y = read x :: [Int] ghci> :t y y :: [Int]
Now when I create that file and do the same thing it comes out as
IO [Int]
?
foo.txt
is a txt file containing only this:12345
Someone that can explain this to me? As I'm about to snap it!
Thanks for any insight!
原文:https://stackoverflow.com/questions/12664050
最满意答案
您可以使用
+
来确保string || 3000
string || 3000
表达式是一个number
:const port: number = +(process.env.PORT || 3000);
You can use
+
to ensure thestring || 3000
expression is anumber
:const port: number = +(process.env.PORT || 3000);
相关问答
更多-
您可能会看到从一般情况下的Typescript编译器增加了执行,副作用是forkJoin没有tuple重载。 将数组表示法从参数列表中删除到forkJoin应该可行,但是: Observable.forkJoin( this.fleetService.getFleet(), this.fleetService.getContractList() ).subscribe( next => { this.fleet = results[0]; this.contractList = ...
-
当你说foo: IFoo = Foo; 你正在将Foo 类分配给IFoo 。 但IFoo接口是由该类的实例实现的。 你需要做的是: foo: IFoo = new Foo; When you say foo: IFoo = Foo; you are assigning the class Foo to IFoo. However the interface IFoo is implemented by instances of that class. You need to do : foo: IFoo ...
-
您可以使用+来确保string || 3000 string || 3000表达式是一个number : const port: number = +(process.env.PORT || 3000); You can use + to ensure the string || 3000 expression is a number: const port: number = +(process.env.PORT || 3000);
-
您需要指定observable的类型: this.event$ = new Observable
(observer => this._observer = observer).share(); 和 this.event_dettaglio$ = new Observable (observer => this._observer_dettaglio = observer).share(); You need to specify the type of ... -
(string|number)[]是一个可以包含字符串或数字元素的数组 string[] | number[] string[] | number[]是一个字符串数组或数组数组。 首先会允许像[1, "2", 3]数组,第二个不会允许它们。 因此,为了您的安全,编译器会抱怨。 解决方案:只使用其中一个。 (string|number)[] is an array that can contain string or number elements string[] | number[] is EITHER ...
-
你试图将this.dishes设置为promise,而它是一个Dish 。 删除代码中的分配并仅在收到数据后设置this.dishes : this.dishService.getDishes() .then(dishes => this.dishes = dishes); You are trying to set this.dishes to a promise while it's a Dish. Remove the assignment in your code and set th ...
-
return Promise.reject
(message) // this line errs with TS2322 .then(() => this.appState.refresh()) .then(() => this.redirects.login()) .then(() => this.alerts.warning("Redirected to login because no credentials found.")); 打字稿对你大喊 ... -
错误TS2322:输入'{id:string;(error TS2322: Type '{ id: string; }' is not assignable to type 'ApiModelFilter
') [2024-01-09]嗯,看起来像一个TypeScript错误(或至少是一个设计限制)。 它与Microsoft / TypeScript#13442有关 ,其中有人感到惊讶的是,没有额外属性的Partial类型的对象文字不能分配给Partial,其中T extends U 现在在这种情况下,它不是一个错误:对于某些K , T[K]可能比U[K]窄,所以你不能将Partial分配给Partial 。 这不是关键问题; 这是价值观。 但是,在您的情况下,您不关心T[K]或U[K]等值类型。 所有你关心的都 ... -
TS 2322 - 类型'{id:number。中缺少属性'id'(TS 2322 - Property 'id' is missing in type '{ id: number)[2023-09-12]
您正在尝试将对象数组分配给Car类型的变量。 使变量成为Cars的数组。 cars : Car[] = [ You are trying to assign an array of objects to a variable of type Car. Make the variable an array of Cars. cars : Car[] = [ -
看起来scan运算符的类型有问题,你看,如果你研究源代码,它实际上是类型
,其中R是默认值的类型。 但是当您在示例中合并observable时,您将获得一个有效的Observable ,因此,您只需键入cast来抑制错误: this.show_dropdown$ = >Observable.merge... //rest of your code 这是有效的,应该消除这些问题 It seems there is a problem wi ...