小编Mar*_*van的帖子

在osx上为GHCJS安装webkitgtk3

我正在尝试在Mac OSX上安装ghcjs-dom软件包.由于存在很多依赖关系,因此它很颠簸.Webkitgtk3是我目前的克星

cabal install ghcjs-dom
Resolving dependencies...
Configuring webkitgtk3-0.14.1.1...
Failed to install webkitgtk3-0.14.1.1
Build log ( /Users/markkaravan/.cabal/logs/webkitgtk3-0.14.1.1.log ):
[1 of 2] Compiling SetupWrapper     ( /var/folders/br/4zwhphlx3816v87cc0bb5sxh0000gn/T/cabal-tmp-24401/webkitgtk3-0.14.1.1/SetupWrapper.hs, /var/folders/br/4zwhphlx3816v87cc0bb5sxh0000gn/T/cabal-tmp-24401/webkitgtk3-0.14.1.1/dist/setup/SetupWrapper.o )
[2 of 2] Compiling Main             ( /var/folders/br/4zwhphlx3816v87cc0bb5sxh0000gn/T/cabal-tmp-24401/webkitgtk3-0.14.1.1/dist/setup/setup.hs, /var/folders/br/4zwhphlx3816v87cc0bb5sxh0000gn/T/cabal-tmp-24401/webkitgtk3-0.14.1.1/dist/setup/Main.o )
Linking /var/folders/br/4zwhphlx3816v87cc0bb5sxh0000gn/T/cabal-tmp-24401/webkitgtk3-0.14.1.1/dist/setup/setup ...
[1 of 2] Compiling Gtk2HsSetup      ( Gtk2HsSetup.hs, dist/setup-wrapper/Gtk2HsSetup.o )
[2 of 2] Compiling Main             ( SetupMain.hs, dist/setup-wrapper/Main.o )
Linking dist/setup-wrapper/setup ...
Configuring webkitgtk3-0.14.1.1...
setup: The pkg-config package 'webkitgtk-3.0' version >=1.8 is required but it
could not be found.
cabal: Error: some …
Run Code Online (Sandbox Code Playgroud)

homebrew haskell webkitgtk ghcjs ghcjs-dom

19
推荐指数
1
解决办法
526
查看次数

haskell的foldr总是采用双参数lambda吗?

Haskell newb在这里

我正在研究haskell中的这个问题:

(**) Eliminate consecutive duplicates of list elements.
If a list contains repeated elements they should be replaced with a single copy of the element. The order of the elements should not be changed.

Example:
* (compress '(a a a a b c c a a d e e e e))
(A B C A D E)
Run Code Online (Sandbox Code Playgroud)

解决方案(我必须查找)使用foldr:

compress' :: (Eq a) => [a] -> [a]
compress' xs = foldr (\x acc -> if x == (head acc) …
Run Code Online (Sandbox Code Playgroud)

haskell fold

8
推荐指数
2
解决办法
3328
查看次数

来自GHC的更多描述性错误消息

我通过GHCI运行了一些代码,并得到了这个错误:

*** Exception: Prelude.!!: index too large
Run Code Online (Sandbox Code Playgroud)

过了一会儿,我继续修复了这个错误(正如你可能想象的那样,由一个太大的索引引起),但是我希望GHC会告诉我这个大索引的评估线是什么.

还有办法吗?

  • A)使GHCI更加冗长,或者
  • B)使用一种常见的做法,以某种方式避免这种错误(当然,害羞使用较小的索引)

indexing error-handling haskell ghci

7
推荐指数
1
解决办法
205
查看次数

GraphQL 中的静态值

有没有办法在 graphql 查询中生成静态值?

例如,假设我有一个user带有名称和电子邮件字段的对象。出于某种原因,我总是希望用户的状态为“已接受”。我怎样才能编写一个查询来完成这个任务?

我想做的事:

query {
  user(id: 1) {
    email
    name
    status: "ACCEPTED"
  }
}
Run Code Online (Sandbox Code Playgroud)

我想要的结果:

{
  "data": {
    "user": {
      "email": "me@myapp.com",
      "name": "me",
      "status": "ACCEPTED"
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

graphql

7
推荐指数
1
解决办法
3972
查看次数

Laravel ORM数组到字符串转换

Laravel 5.3,PHP 5.6新laravel new项目,最小配置.

我做了一个简单的迁移和模型,并试图通过它将数据播种到其中php artisan tinker.

我的迁移看起来像这样:

<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreatesFooTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('foo', function (Blueprint $table) {
            $table->increments('id');
            $table->string('foo', 20);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('foo');
    }
} 
Run Code Online (Sandbox Code Playgroud)

当我运行php artisan migrate数据库时,填充就好了.

相应的模型很简单:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Foo extends …
Run Code Online (Sandbox Code Playgroud)

php orm laravel eloquent

6
推荐指数
2
解决办法
7021
查看次数

模块暴露在Elm 0.18中

我有一个类型的榆木模块,包括类型和类型别名Foo,Bar和Baz.当我导出这样的一切时,代码工作:

module Types exposing (..)

但是,如果我明确包含所有类型,则代码会中断.

module Types exposing (Foo, Bar, Baz)

消费文件上的import语句也是如此; 两者都需要exposing (..)

这两种方法有什么区别?

types elm

6
推荐指数
1
解决办法
253
查看次数

列表中的 Json.Decode.Pipeline (elm 0.18)

我有一个带有嵌套列表的类型别名,我想用Json.Decode.Pipeline.

import Json.Decode as Decode exposing (..)
import Json.Encode as Encode exposing (..)
import Json.Decode.Pipeline as Pipeline exposing (decode, required)

type alias Student =
    { name : String
    , age : Int
    }

type alias CollegeClass =
    { courseId : Int
    , title : String
    , teacher : String
    , students : List Student
    }

collegeClassDecoder : Decoder CollegeClass
collegeClassDecoder =
    decode CollegeClass
        |> Pipeline.required "courseId" Decode.int
        |> Pipeline.required "title" Decode.string
        |> Pipeline.required "teacher" Decode.string
        |> -- what …
Run Code Online (Sandbox Code Playgroud)

json decode elm

5
推荐指数
1
解决办法
824
查看次数

与 Ecto 执行联合

我正在 Phoenix 应用程序中的三个表上运行搜索功能,并且我想使用 SQL 的 UNION 运算符之类的东西来连接它们。

我有三张桌子:

mix phx.gen.json Accounts User users handle:string email:string
mix phx.gen.json Content Post posts title:string content:string
mix phx.gen.json Content Category categories name:string
Run Code Online (Sandbox Code Playgroud)

我们假设没有外键或链接表。

如果我想在 SQL 中对这些进行搜索,我会这样做:

SELECT handle FROM users WHERE handle LIKE "%string%"
UNION
SELECT title FROM posts WHERE title LIKE "%string%"
UNION
SELECT name FROM categories WHERE name LIKE "%string%"
Run Code Online (Sandbox Code Playgroud)

然而,Ecto 2 似乎不支持联合。我想做这样的事情:

query1 =
  from u in User,
    where: ilike(u.handle, ^"%#{str}%"),
    select: u

query2 =
  from p in Post,
    where: ilike(p.title, …
Run Code Online (Sandbox Code Playgroud)

union elixir ecto phoenix-framework

5
推荐指数
1
解决办法
2161
查看次数

在Elm中获取函数的类型签名

我正在使用榆木0.18。

假设我有一个函数,将一堆我匆忙扔到一起的东西串在一起。它可以工作,但是我不确定它的类型签名是什么,我想榆木告诉我(或提示我)该类型签名。

例如,我使用graphql并具有一个接受graphql字符串,解码器(也没有类型签名)和a的Cmd Msg函数,并通过HttpBuilder运行它。

graphQLPost graphiql decoder msg =
    HttpBuilder.post (url ++ "api")
        |> HttpBuilder.withStringBody "text/plain" graphiql
        |> HttpBuilder.withExpect (Http.expectJson decoder)
        |> HttpBuilder.send msg
Run Code Online (Sandbox Code Playgroud)

这行得通,尽管我不知道为什么。我尝试将其与类型签名配合使用graphQLPost : String -> Json.Decode.Decoder -> Cmd Msg,但出现错误。

对我来说,弄清楚这种类型的签名并不像找到一种方法通过榆树诱导它们那样重要。是否可以输入命令elm-repl或可以告诉我签名的内容?

type-inference type-signature elm

5
推荐指数
1
解决办法
213
查看次数

Elixir - 模块未使用docs编译

我昨天刚开始学习长生不老药.我有一个文件User.exs.它看起来像这样:

defmodule User do
    @moduledoc """ 
    Defines the user struct and functions to handle users.
    """
    # functions and stuff go here...

end
Run Code Online (Sandbox Code Playgroud)

当我运行时iex,这是当我尝试查看文档时发生的情况:

iex(1)> c "user.exs"
[User]
iex(2)> h User
User was not compiled with docs
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

documentation elixir iex

4
推荐指数
2
解决办法
1365
查看次数