5 / 5 / 1
Регистрация: 20.09.2015
Сообщений: 86
|
||||||
1 | ||||||
Variable not in scope25.05.2018, 04:30. Показов 8717. Ответов 10
Метки нет (Все метки)
Пытаюсь загрузить модуль в ghci, но выдаёт ошибки
Копипастил и соединял код от сюда: https://mazzo.li/posts/graph-drawing.html Помогите решить проблему, пожалуйста.
0
|
25.05.2018, 04:30 | |
Ответы с готовыми решениями:
10
Ошибка variable is already defined in the scope A local variable named 'n' is already defined in this scope Возникает ошибка Error 1 A local variable named 'c' cannot be declared in this scope because it would give a different m Список с дробями: Variable or field 'input' declared void 'pd' was not declared in this scope |
Модератор
|
||||||
25.05.2018, 06:37 | 2 | |||||
Если вы привели все сообщения и ghci не сообщает что Graphics.Gloss не найден, значит вы пакет gloss установили.
Не знаю какой версии и откуда. Если ставили stack-ом, то на stackage.org в этом пакете функция applyViewPortToPicture есть. Но, возможно, нужно добавить
Посмотрите аналогично на stackage.org по другим не найденным функциям.
1
|
5 / 5 / 1
Регистрация: 20.09.2015
Сообщений: 86
|
|
25.05.2018, 09:17 [ТС] | 3 |
KolodeznyDiver, да, я показал все сообщения.
Спасибо, этот импорт почти помог, осталось только 2 ошибки.. Код
GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help Prelude> :l C:\Users\Egor\Documents\HaskellCoursework\Main.hs [1 of 1] Compiling Main ( C:\Users\Egor\Documents\HaskellCoursework\Main.hs, interpreted ) C:\Users\Egor\Documents\HaskellCoursework\Main.hs:91:61: error: Variable not in scope: graphEdges :: Graph -> Set Edge | 91 | edges = Pictures [drawEdge e sc | e <- Set.toList (graphEdges gr)] | ^^^^^^^^^^ C:\Users\Egor\Documents\HaskellCoursework\Main.hs:101:40: error: * Variable not in scope: normaliseV :: Point -> Vector * Perhaps you meant `normalizeV' (imported from Graphics.Gloss.Data.Vector) | 101 | if l > 0 then (charge / l) `mulSV` normaliseV d else 0 | ^^^^^^^^^^ Failed, no modules loaded. Prelude> Код
C:\Program Files\Haskell Platform\8.2.2\lib\base-4.10.1.0
0
|
Модератор
|
|
25.05.2018, 09:47 | 4 |
Вставить код функции graphEdges из приведённой вами статьи.
normalizeV же написана неправильно, о чём вам компилятор и говорит предлагая правильное написание. Посмотрите внимательно. Так не делают. Дальше тоже проблемы будут. Снесите платформу и установите стек. Правильная установка Haskell. Утилита Stack
1
|
5 / 5 / 1
Регистрация: 20.09.2015
Сообщений: 86
|
|
25.05.2018, 10:05 [ТС] | 5 |
KolodeznyDiver, заменил на normolize, теперь такие ошибки полезли:
Код
C:\Users\Egor\Documents\HaskellCoursework\Main.hs:91:61: error: Variable not in scope: graphEdges :: Graph -> Set Edge | 91 | edges = Pictures [drawEdge e sc | e <- Set.toList (graphEdges gr)] | ^^^^^^^^^^ C:\Users\Egor\Documents\HaskellCoursework\Main.hs:103:9: error: * No instance for (Num Point) arising from a use of `-' * In the expression: v1 - v2 In an equation for `d': d = v1 - v2 In an equation for `pushForce': pushForce v1 v2 = if l > 0 then (charge / l) `mulSV` normalizeV d else 0 where d = v1 - v2 l = magV d ** 2 | 103 | d = v1 - v2 | ^^^^^^^ C:\Users\Egor\Documents\HaskellCoursework\Main.hs:110:38: error: * No instance for (Num Point) arising from a use of `-' * In the second argument of `mulSV', namely `(v2 - v1)' In the expression: stiffness `mulSV` (v2 - v1) In an equation for `pullForce': pullForce v1 v2 = stiffness `mulSV` (v2 - v1) | 110 | pullForce v1 v2 = stiffness `mulSV` (v2 - v1) | ^^^^^^^ C:\Users\Egor\Documents\HaskellCoursework\Main.hs:127:35: error: * No instance for (Num Vector) arising from a use of `+' * In the expression: (getVel pushForce v2pos +) In the first argument of Map.foldr', namely `(\ v2pos -> (getVel pushForce v2pos +))' In the expression: Map.foldr' (\ v2pos -> (getVel pushForce v2pos +)) 0 pts | 127 | push = Map.foldr' (\v2pos -> (getVel pushForce v2pos +)) 0 pts | ^^^^^^^^^^^^^^^^^^^^^^^^ C:\Users\Egor\Documents\HaskellCoursework\Main.hs:128:30: error: * No instance for (Num Vector) arising from a use of `+' * In the expression: (getVel pullForce v2pos +) In the first argument of `foldr', namely `(\ v2pos -> (getVel pullForce v2pos +))' In the expression: foldr (\ v2pos -> (getVel pullForce v2pos +)) 0 [vertexPos v2 sc | v2 <- Set.toList (vertexNeighs v1 gr)] | 128 | pull = foldr (\v2pos -> (getVel pullForce v2pos +)) 0 | ^^^^^^^^^^^^^^^^^^^^^^^^ Failed, no modules loaded.
0
|
5 / 5 / 1
Регистрация: 20.09.2015
Сообщений: 86
|
|
25.05.2018, 11:35 [ТС] | 7 |
KolodeznyDiver, спасибо. А как исправить "No instance for..."?
0
|
Модератор
|
|||||||||||
25.05.2018, 12:12 | 8 | ||||||||||
Сообщение было отмечено Drovosek01 как решение
Решение
Не знаю куда инстанс делся. Проще написать. В начало файла вставляете
1
|
5 / 5 / 1
Регистрация: 20.09.2015
Сообщений: 86
|
||||||
25.05.2018, 12:13 [ТС] | 9 | |||||
KolodeznyDiver, вставил код сразу после импортов, теперь он ругается на нелегальный instance.
Код
C:\Users\Egor\Documents\HaskellCoursework\WindowProg.hs:15:10: error: * Illegal instance declaration for `Num (Float, Float)' (All instance types must be of the form (T a1 ... an) where a1 ... an are *distinct type variables*, and each type variable appears at most once in the instance head. Use FlexibleInstances if you want to disable this.) * In the instance declaration for `Num (Float, Float)' | 15 | instance Num (Float, Float) where | ^^^^^^^^^^^^^^^^^^
0
|
5 / 5 / 1
Регистрация: 20.09.2015
Сообщений: 86
|
|
25.05.2018, 14:06 [ТС] | 11 |
KolodeznyDiver, большое спасибо! Всё заработало.
В ghci импортировал модуль с этим кодом, потом вызвал функцию main и открылось окно с подвижным графом. (конечно костыль лютый, но мне пока пойдёт)
1
|
25.05.2018, 14:06 | |
25.05.2018, 14:06 | |
Помогаю со студенческими работами здесь
11
Request scope или Session scope Можно ли в yii соединить (смержить) scope текущего класса со scope класса родителя? 'arr' was not declared in this scope 'sum' was not declared in this scope такие вот ошибки.( Ошибка 'Run-time error '91': Oject variable or with block variable not set' Искать еще темы с ответами Или воспользуйтесь поиском по форуму: |